use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.BaseMemberExpression that) {
super.visit(that);
boolean notIndirectlyInvoked = !that.getIndirectlyInvoked();
boolean notDirectlyInvoked = !that.getDirectlyInvoked();
TypedDeclaration member = resolveBaseMemberExpression(that, notIndirectlyInvoked);
boolean inferrableAnyway = !notDirectlyInvoked && inferrableAnyway(member);
checkExtendsClauseReference(that, member);
if (member != null && notDirectlyInvoked || inferrableAnyway) {
Tree.TypeArguments tal = that.getTypeArguments();
List<Type> typeArgs;
if (typeConstructorArgumentsInferrable(member, that)) {
typeArgs = new TypeArgumentInference(unit).getInferredTypeArgsForFunctionRef(that, null, inferrableAnyway);
} else if (explicitTypeArguments(member, tal)) {
typeArgs = getTypeArguments(tal, null, member.getTypeParameters());
} else {
typeArgs = new TypeArgumentInference(unit).getInferredTypeArgsForFunctionRef(that, null, inferrableAnyway);
}
if (typeArgs != null) {
tal.setTypeModels(typeArgs);
visitBaseMemberExpression(that, member, typeArgs, tal, null);
// otherwise infer type arguments later
} else if (notDirectlyInvoked) {
visitGenericBaseMemberReference(that, member);
// typeArgumentsImplicit(that);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.Return that) {
super.visit(that);
if (returnType == null) {
// misplaced return statements are already handled by ControlFlowVisitor
// missing return types declarations already handled by TypeVisitor
// that.addError("could not determine expected return type");
} else {
that.setDeclaration(returnDeclaration);
Tree.Expression e = that.getExpression();
if (e == null) {
if (!(returnType instanceof Tree.VoidModifier)) {
if (returnDeclaration instanceof Function) {
that.addError("function must return a value: " + returndesc() + " is not a 'void' function", 12000);
} else {
that.addError("getter must return a value: " + returndesc() + " is a getter");
}
}
} else {
if (returnType instanceof Tree.VoidModifier) {
if (returnDeclaration instanceof Function) {
that.addError("function may not return a value: " + returndesc() + " is a 'void' function", 13000);
} else if (returnDeclaration instanceof TypedDeclaration) {
that.addError("setter may not return a value: " + returndesc() + " is a setter");
} else {
that.addError("class initializer may not return a value");
}
} else {
Type at = e.getTypeModel();
if (at != null) {
Type et = returnType.getTypeModel();
if (returnType instanceof Tree.LocalModifier) {
if (returnDeclaration.isActual()) {
// & RV.checkRefinedMemberTypeAssignable()
if (!isTypeUnknown(et) && !isTypeUnknown(at)) {
checkAssignable(at, et, e, "returned expression must be assignable to inferred return type of " + returndesc(), 2100);
}
} else {
inferReturnType(et, at, e);
}
} else {
if (!isTypeUnknown(et) && !isTypeUnknown(at)) {
checkAssignable(at, et, e, "returned expression must be assignable to return type of " + returndesc(), 2100);
}
}
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class ExpressionVisitor method resolveBaseMemberExpression.
private TypedDeclaration resolveBaseMemberExpression(Tree.BaseMemberExpression that, boolean error) {
Tree.Identifier id = that.getIdentifier();
String name = name(id);
Scope scope = that.getScope();
TypedDeclaration member = getTypedDeclaration(scope, name, that.getSignature(), that.getEllipsis(), that.getUnit());
if (member == null) {
if (!dynamic && !isNativeForWrongBackend(scope, unit) && error) {
that.addError("function or value is not defined: '" + name + "'" + correctionMessage(name, scope, unit, cancellable), 100);
unit.setUnresolvedReferences();
}
} else {
member = (TypedDeclaration) handleAbstractionOrHeader(member, that, error);
that.setDeclaration(member);
if (error) {
if (checkConcreteConstructor(member, that)) {
checkBaseVisibility(that, member, name);
}
}
}
return member;
}
use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class ExpressionVisitor method initOriginalDeclaration.
private void initOriginalDeclaration(Tree.Variable that) {
if (that.getType() instanceof Tree.SyntheticVariable) {
TypedDeclaration td = (TypedDeclaration) that.getDeclarationModel();
Tree.BaseMemberExpression bme = (Tree.BaseMemberExpression) that.getSpecifierExpression().getExpression().getTerm();
TypedDeclaration d = (TypedDeclaration) bme.getDeclaration();
td.setOriginalDeclaration(d);
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class ExpressionVisitor method setFunctionType.
private void setFunctionType(Tree.FunctionModifier local, Type et, Tree.TypedDeclaration that, Tree.Expression e) {
TypedDeclaration dec = that.getDeclarationModel();
handleUncheckedNulls(local, e, dec);
Type t = inferrableType(et);
local.setTypeModel(t);
dec.setType(t);
}
Aggregations