use of org.eclipse.ceylon.model.typechecker.model.UnknownType in project ceylon by eclipse.
the class ExpressionVisitor method getDeclaration.
private TypeDeclaration getDeclaration(Tree.QualifiedMemberOrTypeExpression that, Type pt) {
TypeDeclaration td;
if (that.getStaticMethodReference()) {
Tree.MemberOrTypeExpression primary = (Tree.MemberOrTypeExpression) that.getPrimary();
td = (TypeDeclaration) primary.getDeclaration();
td = td == null ? new UnknownType(unit) : td;
} else {
td = unwrap(pt, that).getDeclaration();
}
if (td != null && td.isNativeImplementation()) {
TypeDeclaration header = (TypeDeclaration) getNativeHeader(td);
if (header != null) {
td = header;
}
}
return td;
}
use of org.eclipse.ceylon.model.typechecker.model.UnknownType in project ceylon by eclipse.
the class DeclarationVisitor method visit.
public void visit(Tree.IterableType that) {
super.visit(that);
if (inExtends) {
final Tree.Type elem = that.getElementType();
Type t = new LazyType(unit) {
Type iterableType() {
final Type elementType;
final boolean atLeastOne;
if (elem == null) {
elementType = unit.getNothingType();
atLeastOne = false;
} else if (elem instanceof Tree.SequencedType) {
Tree.SequencedType set = (Tree.SequencedType) elem;
elementType = set.getType().getTypeModel();
atLeastOne = set.getAtLeastOne();
} else {
elementType = null;
atLeastOne = false;
}
if (elementType != null) {
return atLeastOne ? unit.getNonemptyIterableType(elementType) : unit.getIterableType(elementType);
} else {
Type ut = new UnknownType(unit).getType();
return unit.getIterableType(ut);
}
}
@Override
public boolean isUnknown() {
return false;
}
@Override
public TypeDeclaration initDeclaration() {
return iterableType().getDeclaration();
}
@Override
public Map<TypeParameter, Type> initTypeArguments() {
return iterableType().getTypeArguments();
}
};
that.setTypeModel(t);
}
}
use of org.eclipse.ceylon.model.typechecker.model.UnknownType in project ceylon by eclipse.
the class SupertypeVisitor method checkForUndecidability.
private void checkForUndecidability(Tree.ExtendedType etn, Tree.SatisfiedTypes stn, TypeDeclaration type, Tree.TypeDeclaration that) {
boolean errors = false;
if (stn != null) {
for (Tree.StaticType st : stn.getTypes()) {
Type t = st.getTypeModel();
if (t != null) {
TypeDeclaration td = t.getDeclaration();
if (!(td instanceof UnknownType) && !(td instanceof TypeAlias)) {
if (td == type) {
brokenSatisfiedType(type, st, null);
errors = true;
} else {
List<TypeDeclaration> list = t.isRecursiveRawTypeDefinition(singleton(type));
if (!list.isEmpty()) {
brokenSatisfiedType(type, st, list);
errors = true;
}
}
}
}
}
}
if (etn != null) {
Tree.StaticType et = etn.getType();
if (et != null) {
Type t = et.getTypeModel();
if (t != null) {
TypeDeclaration td = t.getDeclaration();
if (!(td instanceof UnknownType) && !(td instanceof TypeAlias)) {
if (td == type) {
brokenExtendedType(type, et, null);
errors = true;
} else {
List<TypeDeclaration> list = t.isRecursiveRawTypeDefinition(singleton(type));
if (!list.isEmpty()) {
brokenExtendedType(type, et, list);
errors = true;
}
}
}
}
}
}
if (!errors) {
Unit unit = type.getUnit();
List<Type> list = new ArrayList<Type>();
try {
List<Type> supertypes = type.getType().getSupertypes();
for (Type st : supertypes) {
addToIntersection(list, st, unit);
}
// probably unnecessary - if it were
// going to blow up, it would have
// already blown up in addToIntersection()
canonicalIntersection(list, unit);
} catch (DecidabilityException re) {
brokenHierarchy(type, that, unit);
return;
}
try {
type.getType().getUnionOfCases();
} catch (DecidabilityException re) {
brokenSelfType(type, that);
}
if (stn != null) {
for (Tree.StaticType st : stn.getTypes()) {
Type t = st.getTypeModel();
if (t != null) {
if (checkSupertypeVariance(t, type, st)) {
type.getSatisfiedTypes().remove(t);
type.clearProducedTypeCache();
}
}
}
}
if (etn != null) {
Tree.StaticType et = etn.getType();
if (et != null) {
Type t = et.getTypeModel();
if (t != null) {
if (checkSupertypeVariance(t, type, et)) {
type.setExtendedType(unit.getBasicType());
type.clearProducedTypeCache();
}
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.UnknownType in project ceylon by eclipse.
the class TypeVisitor method visit.
@Override
public void visit(Tree.SatisfiedTypes that) {
super.visit(that);
TypeDeclaration td = (TypeDeclaration) that.getScope();
if (td.isAlias()) {
return;
}
List<Tree.StaticType> types = that.getTypes();
List<Type> list = new ArrayList<Type>(types.size());
if (types.isEmpty()) {
that.addError("missing types in satisfies");
}
boolean foundTypeParam = false;
boolean foundClass = false;
boolean foundInterface = false;
for (Tree.StaticType st : types) {
inheritedType(st);
Type type = st.getTypeModel();
if (type != null) {
TypeDeclaration std = type.getDeclaration();
if (std != null && !(std instanceof UnknownType)) {
if (std == td) {
// unnecessary, handled by SupertypeVisitor
// st.addError("directly extends itself: '" +
// td.getName() + "'");
} else if (std instanceof NothingType) {
st.addError("satisfies the bottom type 'Nothing'");
} else if (std instanceof TypeAlias) {
st.addError("satisfies a type alias: '" + type.getDeclaration().getName(unit) + "'");
} else if (std instanceof Constructor) {
// nothing to do
} else if (td instanceof TypeParameter) {
if (foundTypeParam) {
st.addUnsupportedError("type parameter upper bounds are not yet supported in combination with other bounds");
} else if (std instanceof TypeParameter) {
if (foundClass || foundInterface) {
st.addUnsupportedError("type parameter upper bounds are not yet supported in combination with other bounds");
}
foundTypeParam = true;
list.add(type);
} else if (std instanceof Class) {
if (foundClass) {
st.addUnsupportedError("multiple class upper bounds are not yet supported");
}
foundClass = true;
list.add(type);
} else if (std instanceof Interface) {
foundInterface = true;
list.add(type);
} else {
st.addError("upper bound must be a class, interface, or type parameter");
}
} else {
if (std instanceof TypeParameter) {
st.addError("directly satisfies type parameter: '" + std.getName(unit) + "'");
} else if (std instanceof Class) {
st.addError("satisfies a class: '" + std.getName(unit) + "'");
} else if (std instanceof Interface) {
if (td.isDynamic() && !std.isDynamic()) {
st.addError("dynamic interface satisfies a non-dynamic interface: '" + std.getName(unit) + "'");
} else {
list.add(type);
}
} else {
st.addError("satisfied type must be an interface");
}
}
}
}
}
td.setSatisfiedTypes(list);
}
use of org.eclipse.ceylon.model.typechecker.model.UnknownType in project ceylon by eclipse.
the class TypeVisitor method visit.
@Override
public void visit(Tree.EntryType that) {
super.visit(that);
Type kt = that.getKeyType().getTypeModel();
Type vt = that.getValueType() == null ? new UnknownType(unit).getType() : that.getValueType().getTypeModel();
that.setTypeModel(unit.getEntryType(kt, vt));
}
Aggregations