Search in sources :

Example 1 with UnknownType

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

Example 2 with UnknownType

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);
    }
}
Also used : UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) TypeVisitor.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor.getTupleType) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 3 with UnknownType

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();
                    }
                }
            }
        }
    }
}
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 4 with UnknownType

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);
}
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 5 with UnknownType

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));
}
Also used : 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)

Aggregations

UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)15 Type (org.eclipse.ceylon.model.typechecker.model.Type)10 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)9 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)6 NothingType (org.eclipse.ceylon.model.typechecker.model.NothingType)5 ArrayList (java.util.ArrayList)4 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)4 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)4 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)4 LazyClass (org.eclipse.ceylon.model.loader.model.LazyClass)3 LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)3 Class (org.eclipse.ceylon.model.typechecker.model.Class)3 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)3 TypeAlias (org.eclipse.ceylon.model.typechecker.model.TypeAlias)3 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)3 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)2 AnalyzerUtil.setTypeConstructor (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.setTypeConstructor)2 AnalyzerUtil.unwrapAliasedTypeConstructor (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.unwrapAliasedTypeConstructor)2 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)2 ReflectionClass (org.eclipse.ceylon.model.loader.impl.reflect.mirror.ReflectionClass)2