Search in sources :

Example 76 with Type

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.ForComprehensionClause that) {
    super.visit(that);
    that.setPossiblyEmpty(true);
    Tree.ComprehensionClause cc = that.getComprehensionClause();
    if (cc != null) {
        that.setTypeModel(cc.getTypeModel());
        Tree.ForIterator fi = that.getForIterator();
        if (fi != null) {
            Tree.SpecifierExpression se = fi.getSpecifierExpression();
            if (se != null) {
                Tree.Expression e = se.getExpression();
                if (e != null) {
                    Type it = e.getTypeModel();
                    if (it != null) {
                        checkIterable(it, e);
                        that.setPossiblyEmpty(cc.getPossiblyEmpty() || !unit.isNonemptyIterableType(it));
                        Type absentType = unit.getAbsentType(it);
                        if (absentType == null) {
                            absentType = unit.getNullType();
                        }
                        Type firstType = unionType(absentType, cc.getFirstTypeModel(), unit);
                        that.setFirstTypeModel(firstType);
                    }
                }
            }
        }
    }
}
Also used : 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) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 77 with Type

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.Throw that) {
    super.visit(that);
    Tree.Expression e = that.getExpression();
    if (e != null) {
        Type et = e.getTypeModel();
        if (!isTypeUnknown(et)) {
            Type tt = unit.getThrowableType();
            checkAssignable(et, tt, e, "thrown expression must be a throwable");
        }
    }
}
Also used : 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) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 78 with Type

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

the class ExpressionVisitor method visitInOperator.

private void visitInOperator(Tree.InOp that) {
    Type lhst = leftType(that);
    Type rhst = rightType(that);
    if (!isTypeUnknown(rhst) && !isTypeUnknown(lhst)) {
        Type ct = rhst.getSupertype(unit.getJavaCollectionDeclaration());
        if (ct == null) {
            ct = checkSupertype(rhst, unit.getCategoryDeclaration(), that.getRightTerm(), "operand expression must be a category");
            Type et = unit.getIteratedType(rhst);
            if (et != null && intersectionType(lhst, et, unit).isNothing() && !(lhst.isString() && rhst.isString())) {
                that.addUsageWarning(Warning.disjointContainment, "tests containment with disjoint element types: '" + lhst.asString(unit) + "' and '" + et.asString(unit) + "' are disjoint");
            }
        }
        if (ct != null) {
            Type at = ct.getTypeArguments().isEmpty() ? null : ct.getTypeArgumentList().get(0);
            checkAssignable(lhst, at, that.getLeftTerm(), "operand expression must be assignable to category type");
        }
    }
    that.setTypeModel(unit.getBooleanType());
}
Also used : 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)

Example 79 with Type

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

the class ExpressionVisitor method substitutions.

private static Map<TypeParameter, Type> substitutions(FunctionOrValue refined, FunctionOrValue member) {
    if (refined instanceof Function) {
        Function refinedMethod = (Function) refined;
        Function method = (Function) member;
        List<TypeParameter> refinedParams = refinedMethod.getTypeParameters();
        List<TypeParameter> params = method.getTypeParameters();
        Map<TypeParameter, Type> result = new HashMap<TypeParameter, Type>(params.size());
        for (int i = 0; i < refinedParams.size() && i < params.size(); i++) {
            result.put(refinedParams.get(i), params.get(i).getType());
        }
        return result;
    } else {
        return NO_SUBSTITUTIONS;
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) 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) HashMap(java.util.HashMap) AnalyzerUtil.checkCasesDisjoint(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint) ModelUtil.argumentSatisfiesEnumeratedConstraint(org.eclipse.ceylon.model.typechecker.model.ModelUtil.argumentSatisfiesEnumeratedConstraint)

Example 80 with Type

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

the class ExpressionVisitor method visitGenericQualifiedTypeReference.

private void visitGenericQualifiedTypeReference(Tree.QualifiedTypeExpression that, Type outerType, TypeDeclaration type) {
    if (type instanceof Class && type.isParameterized()) {
        Class generic = (Class) type;
        Scope scope = that.getScope();
        Type target = outerType.getTypeMember(type, typeParametersAsArgList(generic));
        that.setTarget(target);
        Type functionType = genericFunctionType(generic, scope, type, target, unit);
        that.setTypeModel(functionType);
        checkNotJvm(that, "type functions are not supported on the JVM: '" + type.getName(unit) + "' is generic (specify explicit type arguments)");
    }
}
Also used : 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) ModelUtil.findMatchingOverloadedClass(org.eclipse.ceylon.model.typechecker.model.ModelUtil.findMatchingOverloadedClass) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Aggregations

Type (org.eclipse.ceylon.model.typechecker.model.Type)692 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)270 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)263 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)244 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)225 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)207 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)182 AnalyzerUtil.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType)176 AnalyzerUtil.spreadType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType)176 ModelUtil.unionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType)169 ModelUtil.genericFunctionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType)153 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)130 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)125 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)114 ArrayList (java.util.ArrayList)106 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)100 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)96 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)95 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)94 Class (org.eclipse.ceylon.model.typechecker.model.Class)87