use of org.eclipse.ceylon.model.typechecker.model.TypeAlias 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.TypeAlias in project ceylon by eclipse.
the class InheritanceVisitor method validateSupertypes.
private void validateSupertypes(Node that, TypeDeclaration td) {
if (!(td instanceof TypeAlias)) {
List<Type> supertypes = td.getType().getSupertypes();
for (int i = 0; i < supertypes.size(); i++) {
Type st1 = supertypes.get(i);
for (int j = i + 1; j < supertypes.size(); j++) {
Type st2 = supertypes.get(j);
// Note: sets td.inconsistentType by side-effect
checkSupertypeIntersection(that, td, st1, st2);
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeAlias 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.TypeAlias in project ceylon by eclipse.
the class TypeVisitor method visit.
@Override
public void visit(Tree.TypeConstructor that) {
super.visit(that);
TypeAlias ta = that.getDeclarationModel();
ta.setExtendedType(that.getType().getTypeModel());
Type type = ta.getType();
type.setTypeConstructor(true);
that.setTypeModel(type);
}
use of org.eclipse.ceylon.model.typechecker.model.TypeAlias in project ceylon by eclipse.
the class GenerateJsVisitor method addAliasDeclarationToPrototype.
private void addAliasDeclarationToPrototype(TypeDeclaration outer, Tree.TypeAliasDeclaration that) {
comment(that);
final TypeAlias d = that.getDeclarationModel();
String path = qualifiedPath(that, d, true);
if (path.length() > 0) {
path += '.';
}
String tname = names.name(d);
tname = tname.substring(0, tname.length() - 2);
String _tmp = names.createTempVariable();
out(names.self(outer), ".", tname, "=function(){var ");
Type pt = that.getTypeSpecifier().getType().getTypeModel();
boolean skip = true;
if (pt.involvesTypeParameters() && outerSelf(d)) {
out("=this,");
skip = false;
}
out(_tmp, "=");
TypeUtils.typeNameOrList(that, pt, this, skip);
out(";", _tmp, ".$crtmm$=");
TypeUtils.encodeForRuntime(that, d, this);
out(";return ", _tmp, ";}");
endLine(true);
}
Aggregations