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);
}
}
}
}
}
}
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");
}
}
}
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());
}
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;
}
}
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)");
}
}
Aggregations