use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class ExpressionVisitor method setTypeForGuardedVariable.
private void setTypeForGuardedVariable(Tree.Variable var, Tree.ConditionList conditionList, boolean reversed) {
Tree.Condition c = conditionList.getConditions().get(0);
Tree.SpecifierExpression se = var.getSpecifierExpression();
if (c instanceof Tree.ExistsCondition) {
Tree.ExistsCondition ec = (Tree.ExistsCondition) c;
inferDefiniteType(var, se, ec.getNot() ^ reversed);
} else if (c instanceof Tree.NonemptyCondition) {
Tree.NonemptyCondition nec = (Tree.NonemptyCondition) c;
inferNonemptyType(var, se, nec.getNot() ^ reversed);
} else if (c instanceof Tree.IsCondition) {
Tree.IsCondition ic = (Tree.IsCondition) c;
Tree.Expression ex = se.getExpression();
Type expressionType = ex.getTypeModel();
Type type = ic.getType().getTypeModel();
Type narrowedType = narrow(type, expressionType, ic.getNot() ^ reversed);
Value dec = var.getDeclarationModel();
if (!isCompletelyVisible(dec, narrowedType)) {
narrowedType = expressionType;
}
Tree.Type local = var.getType();
local.setTypeModel(narrowedType);
dec.setType(narrowedType);
if (local instanceof Tree.LocalModifier && handlesNull(ic, type) && hasUncheckedNulls(ex)) {
handleUncheckedNulls((Tree.LocalModifier) local, narrowedType, ex, dec);
} else {
dec.setUncheckedNullType(false);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.AttributeArgument that) {
Tree.SpecifierExpression se = that.getSpecifierExpression();
Tree.Type type = that.getType();
Value val = that.getDeclarationModel();
if (se == null) {
Declaration od = beginReturnDeclaration(val);
Tree.Type rt = beginReturnScope(type);
super.visit(that);
endReturnScope(rt, val);
endReturnDeclaration(od);
} else {
super.visit(that);
inferType(that, se);
if (type != null) {
Type t = type.getTypeModel();
if (!isTypeUnknown(t)) {
checkType(t, val, se, 2100);
}
}
}
if (type instanceof Tree.LocalModifier) {
if (isTypeUnknown(type.getTypeModel())) {
if (se == null || !hasError(se)) {
Node node = type.getToken() == null ? that : type;
node.addError("argument type could not be inferred");
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class ExpressionVisitor method checkAssignability.
private void checkAssignability(Tree.Term that, Node node) {
if (that instanceof Tree.QualifiedMemberOrTypeExpression || that instanceof Tree.BaseMemberOrTypeExpression) {
Tree.StaticMemberOrTypeExpression smte = (Tree.StaticMemberOrTypeExpression) that;
Declaration dec = smte.getDeclaration();
if (dec != null && (!isEffectivelyBaseMemberExpression(smte) || (dec instanceof Value && ((Value) dec).isInferred()) || !unit.equals(dec.getUnit()))) {
// Note: other cases handled in SpecificationVisitor
if (dec instanceof Value) {
Value value = (Value) dec;
if (!value.isVariable() && !value.isLate()) {
that.addError("value is not a variable: '" + dec.getName(unit) + "'", 800);
}
} else {
that.addError("not a variable value: '" + dec.getName(unit) + "'");
}
}
if (that instanceof Tree.QualifiedMemberOrTypeExpression) {
Tree.QualifiedMemberOrTypeExpression qmte = (Tree.QualifiedMemberOrTypeExpression) that;
Tree.MemberOperator mo = qmte.getMemberOperator();
if (!(mo instanceof Tree.MemberOp)) {
that.addUnsupportedError("assignment to expression involving ?. or *. not supported");
}
}
} else if (that instanceof Tree.IndexExpression) {
} else {
that.addError("expression cannot be assigned");
}
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class ExpressionVisitor method refineAttribute.
private void refineAttribute(Tree.SpecifierStatement that) {
Value refinedValue = (Value) that.getRefined();
Value value = (Value) that.getDeclaration();
ClassOrInterface ci = (ClassOrInterface) value.getContainer();
Declaration root = refinedValue.getRefinedDeclaration();
TypeDeclaration td = (TypeDeclaration) root.getContainer();
List<Declaration> interveningRefinements = getInterveningRefinements(value, root, ci, td);
accountForIntermediateRefinements(that, refinedValue, value, ci, interveningRefinements);
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class ExpressionVisitor method inferrableParameters.
/**
* Get the parameters of a callable parameter, or, if
* the given parameter is a value parameter of type
* X(Y), a single faked parameter with the name 'it'.
*/
private List<Parameter> inferrableParameters(Parameter param) {
FunctionOrValue model = param.getModel();
if (model instanceof Function) {
Function fun = (Function) model;
ParameterList fpl = fun.getFirstParameterList();
return fpl == null ? null : fpl.getParameters();
} else if (model instanceof Value) {
Type type = param.getType();
if (type != null) {
Type callable = intersectionType(type.resolveAliases(), appliedType(unit.getCallableDeclaration(), unit.getAnythingType(), unit.getNothingType()), unit);
if (callable.isCallable()) {
Type tup = unit.getCallableTuple(callable);
int min = unit.getTupleMinimumLength(tup);
int max = unit.getTupleMaximumLength(tup);
if (min == 1 || max == 1) {
Parameter p = new Parameter();
p.setName("it");
return Collections.<Parameter>singletonList(p);
} else if (min == 0) {
return Collections.<Parameter>emptyList();
}
}
}
return null;
} else {
return null;
}
}
Aggregations