use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class TypePrinter method abbreviateEntry.
public static boolean abbreviateEntry(Type pt) {
if (pt.isEntry() && pt.getTypeArgumentList().size() == 2) {
Unit unit = pt.getDeclaration().getUnit();
Type kt = unit.getKeyType(pt);
Type vt = unit.getValueType(pt);
return kt != null && vt != null && !kt.isEntry() && !vt.isEntry();
/*&&
kt.isPrimitiveAbbreviatedType() &&
vt.isPrimitiveAbbreviatedType();*/
} else {
return false;
}
}
use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class ExpressionVisitor method accountForIntermediateRefinements.
private Reference accountForIntermediateRefinements(Tree.SpecifierStatement that, FunctionOrValue refinedMethodOrValue, FunctionOrValue methodOrValue, ClassOrInterface refiningType, List<Declaration> interveningRefinements) {
// accumulate an intersection of the types of
// everything it refines
List<Type> refinedTypes = new ArrayList<Type>();
// don't check this one here because it is
// separately checked in visit(SpecifierStatement)
Reference refinedProducedReference = getRefinedMemberReference(refinedMethodOrValue, refiningType);
Map<TypeParameter, Type> substs = substitutions(refinedMethodOrValue, methodOrValue);
Type refinedType = refinedProducedReference.getType().substitute(substs, null);
boolean allHaveNulls = hasNullReturnValues(refinedType, refinedMethodOrValue);
intersectReturnType(refinedTypes, refinedType);
for (Declaration intervening : interveningRefinements) {
if (intervening instanceof FunctionOrValue && // factors here as well?
!refinedMethodOrValue.equals(intervening)) {
FunctionOrValue refinement = (FunctionOrValue) intervening;
Reference refinedMember = getRefinedMemberReference(refinement, refiningType);
Map<TypeParameter, Type> subs = substitutions(refinement, methodOrValue);
Type type = refinedMember.getType().substitute(subs, null);
allHaveNulls = allHaveNulls && hasNullReturnValues(type, refinement);
intersectReturnType(refinedTypes, type);
checkIntermediateRefinement(that, refinement, refinedMember);
}
}
Type it = canonicalIntersection(refinedTypes, unit);
if (allHaveNulls && !unit.isOptionalType(it)) {
methodOrValue.setUncheckedNullType(true);
Tree.Term lhs = that.getBaseMemberExpression();
// TODO: this is pretty ugly, think of something better!
lhs.setTypeModel(unit.getOptionalType(lhs.getTypeModel()));
}
methodOrValue.setType(it);
return refinedProducedReference;
}
use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class ExpressionVisitor method setMetamodelType.
private void setMetamodelType(Tree.MemberLiteral that, Declaration result) {
Type outerType;
if (result.isClassOrInterfaceMember()) {
Tree.StaticType type = that.getType();
outerType = type == null ? that.getScope().getDeclaringType(result) : type.getTypeModel();
} else {
outerType = null;
}
boolean constructor = isConstructor(result);
if (result instanceof Function) {
Function method = (Function) result;
if (method.isAbstraction()) {
that.addError("method is overloaded");
} else {
Tree.TypeArgumentList tal = that.getTypeArgumentList();
if (explicitTypeArguments(method, tal)) {
List<Type> typeArgs = getTypeArguments(tal, outerType, method.getTypeParameters());
if (tal != null) {
tal.setTypeModels(typeArgs);
}
if (acceptsTypeArguments(method, outerType, typeArgs, tal, that) || true) {
TypedReference pr = outerType == null ? method.appliedTypedReference(null, typeArgs) : outerType.getTypedMember(method, typeArgs);
that.setTarget(pr);
Type metatype = constructor ? unit.getConstructorMetatype(pr) : unit.getFunctionMetatype(pr);
that.setTypeModel(metatype);
}
} else {
that.addError("missing type arguments to generic declaration: '" + method.getName(unit) + "'");
}
}
} else if (result instanceof Value) {
Value value = (Value) result;
if (that.getTypeArgumentList() != null) {
that.addError("does not accept type arguments: '" + result.getName(unit) + "' is a value");
} else {
TypedReference reference = value.appliedTypedReference(outerType, NO_TYPE_ARGS);
that.setTarget(reference);
Type metatype = constructor ? unit.getValueConstructorMetatype(reference) : unit.getValueMetatype(reference);
that.setTypeModel(metatype);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class ExpressionVisitor method inferParameterTypesIndirectly.
/**
* Infer parameter types of anonymous function arguments
* in an indirect invocation with positional arguments.
*/
private boolean[] inferParameterTypesIndirectly(Tree.PositionalArgumentList pal, Type type, boolean error) {
List<Tree.PositionalArgument> args = pal.getPositionalArguments();
int argCount = args.size();
boolean[] delayed = new boolean[argCount];
if (unit.isCallableType(type)) {
List<Type> paramTypes = unit.getCallableArgumentTypes(type);
int paramsSize = paramTypes.size();
for (int i = 0; i < paramsSize && i < argCount; i++) {
Type paramType = paramTypes.get(i);
paramType = callableFromUnion(paramType);
Tree.PositionalArgument arg = args.get(i);
if (arg instanceof Tree.ListedArgument && unit.isCallableType(paramType)) {
Tree.ListedArgument la = (Tree.ListedArgument) arg;
Tree.Expression e = la.getExpression();
if (e != null) {
Tree.Term term = unwrapExpressionUntilTerm(e.getTerm());
if (term instanceof Tree.FunctionArgument) {
Tree.FunctionArgument fa = (Tree.FunctionArgument) term;
delayed[i] = !inferParameterTypesFromCallableType(paramType, null, fa, error);
} else if (term instanceof Tree.StaticMemberOrTypeExpression) {
Tree.StaticMemberOrTypeExpression smte = (Tree.StaticMemberOrTypeExpression) term;
smte.setParameterType(paramType);
}
}
}
}
}
return delayed;
}
use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class ExpressionVisitor method checkComprehensionIndirectArgument.
private void checkComprehensionIndirectArgument(Tree.Comprehension c, Type paramType, boolean atLeastOne) {
Tree.InitialComprehensionClause icc = c.getInitialComprehensionClause();
if (icc.getPossiblyEmpty() && atLeastOne) {
c.addError("variadic parameter is required but comprehension is possibly empty");
}
Type at = c.getTypeModel();
Type set = paramType == null ? null : unit.getIteratedType(paramType);
if (!isTypeUnknown(at) && !isTypeUnknown(set)) {
checkAssignable(at, set, c, "argument must be assignable to variadic parameter");
}
}
Aggregations