Search in sources :

Example 56 with Scope

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

the class ExpressionVisitor method visitGenericBaseMemberReference.

private void visitGenericBaseMemberReference(Tree.StaticMemberOrTypeExpression that, TypedDeclaration member) {
    if (member instanceof Function && member.isParameterized()) {
        Function generic = (Function) member;
        Scope scope = that.getScope();
        Type outerType = scope.getDeclaringType(member);
        TypedReference target = member.appliedTypedReference(outerType, NO_TYPE_ARGS);
        that.setTarget(target);
        Type functionType = genericFunctionType(generic, scope, member, target, unit);
        that.setTypeModel(functionType);
        checkNotJvm(that, "type functions are not supported on the JVM: '" + member.getName(unit) + "' is generic (specify explicit type arguments)");
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) 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) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) NativeUtil.declarationScope(org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.declarationScope) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference)

Example 57 with Scope

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

the class InheritanceVisitor method checkExtensionOfMemberType.

private void checkExtensionOfMemberType(Node that, TypeDeclaration td, Type type) {
    Type qt = type.getQualifyingType();
    if (qt != null && td instanceof ClassOrInterface) {
        Unit unit = that.getUnit();
        TypeDeclaration d = type.getDeclaration();
        if (d.isStatic() || d instanceof Constructor) {
            checkExtensionOfMemberType(that, td, qt);
        } else {
            Scope s = td;
            while (s != null) {
                s = s.getContainer();
                if (s instanceof TypeDeclaration) {
                    TypeDeclaration otd = (TypeDeclaration) s;
                    if (otd.getType().isSubtypeOf(qt)) {
                        return;
                    }
                }
            }
            that.addError("qualifying type '" + qt.asString(unit) + "' of supertype '" + type.asString(unit) + "' is not an outer type or supertype of any outer type of '" + td.getName(unit) + "'");
        }
    }
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) Type(org.eclipse.ceylon.model.typechecker.model.Type) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 58 with Scope

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

the class InheritanceVisitor method visit.

@Override
public void visit(Tree.Enumerated that) {
    super.visit(that);
    Value v = that.getDeclarationModel();
    Scope container = v.getContainer();
    if (container instanceof Class) {
        Class cl = (Class) container;
        List<TypedDeclaration> caseValues = cl.getCaseValues();
        if (caseValues != null && !caseValues.contains(v) && !cl.isAbstract()) {
            that.addError("value constructor is not a case of enumerated class: '" + v.getName() + "' is not listed in the 'of' clause of '" + cl.getName() + "'");
        }
    }
}
Also used : AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Value(org.eclipse.ceylon.model.typechecker.model.Value) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Example 59 with Scope

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

the class InheritanceVisitor method collectCaseValues.

void collectCaseValues(Tree.CaseTypes that, TypeDeclaration td) {
    Unit unit = that.getUnit();
    Set<Declaration> valueSet = new HashSet<Declaration>();
    for (Tree.StaticMemberOrTypeExpression bme : that.getBaseMemberExpressions()) {
        String name = name(bme.getIdentifier());
        TypedDeclaration value = bme instanceof Tree.BaseMemberExpression ? getTypedDeclaration(bme.getScope(), name, null, false, unit) : getPackageTypedDeclaration(name, null, false, unit);
        if (value != null) {
            if (value != null && !valueSet.add(value)) {
                // this error is not really truly necessary
                bme.addError("duplicate case: '" + value.getName(unit) + "' of '" + td.getName() + "'");
            }
            Type type = value.getType();
            if (type != null) {
                TypeDeclaration caseDec = type.getDeclaration();
                if (caseDec instanceof Constructor) {
                    Scope scope = caseDec.getContainer();
                    if (scope instanceof Class) {
                        // enumerated singleton constructors
                        Constructor cons = (Constructor) caseDec;
                        Class c = (Class) scope;
                        if (!c.isToplevel() && !c.isStatic()) {
                            bme.addError("case must be a value constructor of a toplevel or static class: '" + c.getName(unit) + "' is not toplevel");
                        } else if (!cons.getParameterLists().isEmpty()) {
                            bme.addError("case must be a value constructor of a toplevel or static class: '" + cons.getName(unit) + "' is not a value constructor");
                        }
                    /*else if (!c.inherits(unit.getIdentifiableDeclaration())) {
                                bme.addError("case must be a value constructor of an identifiable class: '" + 
                                        c.getName(unit) + 
                                        "' is not a subtype of 'Identifiable'");
                            }*/
                    }
                } else {
                    // enumerated anonymous subclasses
                    if (!caseDec.isObjectClass()) {
                        bme.addError("case must be a toplevel or static anonymous class: '" + value.getName(unit) + "' is not an anonymous class");
                    } else if (!value.isToplevel() && !value.isStatic()) {
                        bme.addError("case must be a toplevel or static anonymous class: '" + value.getName(unit) + "' is neither static nor toplevel");
                    }
                }
                if (checkDirectSubtype(td, bme, type)) {
                    checkAssignable(type, td.getType(), bme, getCaseTypeExplanation(td, type));
                }
            }
        }
    }
}
Also used : AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) Type(org.eclipse.ceylon.model.typechecker.model.Type) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) HashSet(java.util.HashSet)

Example 60 with Scope

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

the class InheritanceVisitor method visit.

@Override
public void visit(Tree.Constructor that) {
    super.visit(that);
    Constructor c = that.getConstructor();
    Scope container = c.getContainer();
    if (container instanceof Class) {
        Class cl = (Class) container;
        List<TypedDeclaration> caseValues = cl.getCaseValues();
        if (caseValues != null && !c.isAbstract() && !cl.isAbstract()) {
            that.addError("concrete enumerated class may not have non-partial callable constructor: enumerated class '" + cl.getName() + "' is not abstract and constructor '" + c.getName() + "' is not partial");
        }
    }
}
Also used : AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Aggregations

Scope (org.eclipse.ceylon.model.typechecker.model.Scope)142 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)71 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)57 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)50 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)44 Type (org.eclipse.ceylon.model.typechecker.model.Type)44 ConditionScope (org.eclipse.ceylon.model.typechecker.model.ConditionScope)35 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)34 Class (org.eclipse.ceylon.model.typechecker.model.Class)33 ModelUtil.getRealScope (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope)31 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)30 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)26 Value (org.eclipse.ceylon.model.typechecker.model.Value)26 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)25 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)24 Function (org.eclipse.ceylon.model.typechecker.model.Function)23 Package (org.eclipse.ceylon.model.typechecker.model.Package)22 ArrayList (java.util.ArrayList)21 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)20 NativeUtil.declarationScope (org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.declarationScope)15