Search in sources :

Example 11 with TypeAlias

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();
                    }
                }
            }
        }
    }
}
Also used : UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) Type(org.eclipse.ceylon.model.typechecker.model.Type) DecidabilityException(org.eclipse.ceylon.model.typechecker.model.DecidabilityException) ArrayList(java.util.ArrayList) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 12 with TypeAlias

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);
            }
        }
    }
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) AnalyzerUtil.checkCasesDisjoint(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint)

Example 13 with TypeAlias

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);
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) AnalyzerUtil.setTypeConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.setTypeConstructor) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) AnalyzerUtil.unwrapAliasedTypeConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.unwrapAliasedTypeConstructor) ArrayList(java.util.ArrayList) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.isVeryAbstractClass(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isVeryAbstractClass) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)

Example 14 with TypeAlias

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);
}
Also used : NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias)

Example 15 with TypeAlias

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);
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ExtendedType(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ExtendedType) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias)

Aggregations

TypeAlias (org.eclipse.ceylon.model.typechecker.model.TypeAlias)32 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)23 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)20 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)16 Class (org.eclipse.ceylon.model.typechecker.model.Class)15 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)14 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)13 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)13 Type (org.eclipse.ceylon.model.typechecker.model.Type)12 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)11 Function (org.eclipse.ceylon.model.typechecker.model.Function)10 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)9 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)9 ArrayList (java.util.ArrayList)8 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)8 Value (org.eclipse.ceylon.model.typechecker.model.Value)8 NothingType (org.eclipse.ceylon.model.typechecker.model.NothingType)6 LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)5 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)5 Package (org.eclipse.ceylon.model.typechecker.model.Package)5