Search in sources :

Example 1 with DecidabilityException

use of org.eclipse.ceylon.model.typechecker.model.DecidabilityException 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 2 with DecidabilityException

use of org.eclipse.ceylon.model.typechecker.model.DecidabilityException in project ceylon by eclipse.

the class DefaultTypeArgVisitor method visit.

@Override
public void visit(Tree.TypeParameterDeclaration that) {
    Tree.TypeSpecifier ts = that.getTypeSpecifier();
    if (ts != null) {
        TypeParameter tp = that.getDeclarationModel();
        Declaration dec = tp.getDeclaration();
        Type dta = tp.getDefaultTypeArgument();
        if (dta != null) {
            try {
                if (dta.involvesDeclaration(dec)) {
                    tp.setDefaultTypeArgument(null);
                }
            } catch (DecidabilityException re) {
                ts.addError("undecidable default type argument");
                tp.setDefaultTypeArgument(null);
            }
        }
    }
    super.visit(that);
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Type(org.eclipse.ceylon.model.typechecker.model.Type) DecidabilityException(org.eclipse.ceylon.model.typechecker.model.DecidabilityException) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Aggregations

Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)2 DecidabilityException (org.eclipse.ceylon.model.typechecker.model.DecidabilityException)2 Type (org.eclipse.ceylon.model.typechecker.model.Type)2 ArrayList (java.util.ArrayList)1 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)1 TypeAlias (org.eclipse.ceylon.model.typechecker.model.TypeAlias)1 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)1 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)1 Unit (org.eclipse.ceylon.model.typechecker.model.Unit)1 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)1