use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class DeclarationVisitor method checkForDuplicateDeclaration.
private static void checkForDuplicateDeclaration(Tree.Declaration that, Declaration model, Scope scope) {
String name = model.getName();
Unit unit = model.getUnit();
if (name != null) {
if (model instanceof Setter) {
Setter setter = (Setter) model;
checkGetterForSetter(that, setter, scope);
} else {
// this isn't the correct scope for declaration
// which follow an assertion, since it misses
// condition scopes, so use the argument scope
// Scope scope = model.getContainer();
boolean isControl;
do {
Declaration member = scope.getDirectMember(name, null, false);
if (member != null && member != model) {
boolean dup = false;
boolean possibleOverloadedMethod = member instanceof Function && model instanceof Function && scope instanceof ClassOrInterface && !member.isNative() && member.isShared() && model.isShared();
boolean legalOverloadedMethod = possibleOverloadedMethod;
if (legalOverloadedMethod) {
// anticipate that it might be
// an overloaded method - then
// further checking happens in
// RefinementVisitor
initFunctionOverload((Function) model, (Function) member, scope, unit);
} else if (canBeNative(member) && canBeNative(model) && model.isNative()) {
// just to make sure no error
// gets reported
} else {
dup = true;
if (possibleOverloadedMethod) {
// it as overloading anyway
if (initFunctionOverload((Function) model, (Function) member, scope, unit)) {
that.addError("duplicate declaration: the name '" + name + "' is not unique in this scope");
}
} else {
that.addError("duplicate declaration: the name '" + name + "' is not unique in this scope");
}
}
if (dup) {
unit.getDuplicateDeclarations().add(member);
}
}
isControl = scope instanceof ControlBlock;
scope = scope.getContainer();
} while (isControl);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class ExpressionVisitor method createInferredParameter.
/**
* Create a model for an inferred parameter of an
* anonymous function.
*/
private boolean createInferredParameter(Tree.FunctionArgument anon, Declaration declaration, Tree.Parameter ap, Parameter parameter, Type type, FunctionOrValue original, boolean error) {
if (isTypeUnknown(type)) {
type = unit.getUnknownType();
if (!dynamic) {
if (error) {
ap.addError("could not infer parameter type: '" + parameter.getName() + "' would have unknown type");
} else {
return false;
}
}
} else if (involvesTypeParams(declaration, type)) {
if (error) {
type = unit.getUnknownType();
ap.addError("could not infer parameter type: '" + parameter.getName() + "' would have type '" + type.asString(unit) + "' involving type parameters");
} else {
return false;
}
}
Value model = (Value) parameter.getModel();
if (model == null) {
model = new Value();
model.setUnit(unit);
model.setName(parameter.getName());
model.setOriginalParameterDeclaration(original);
parameter.setModel(model);
Function m = anon.getDeclarationModel();
model.setContainer(m);
model.setScope(m);
m.addMember(model);
}
model.setType(type);
model.setInferred(true);
if (declaration != null && type != null && declaration.isJava() && !type.isUnknown() && type.isSubtypeOf(unit.getObjectType()) && canHaveUncheckedNulls(type)) {
model.setUncheckedNullType(true);
}
model.setInitializerParameter(parameter);
if (ap instanceof Tree.ValueParameterDeclaration) {
Tree.ValueParameterDeclaration vpd = (Tree.ValueParameterDeclaration) ap;
vpd.getTypedDeclaration().getType().setTypeModel(type);
}
return true;
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class TypeVisitor method visit.
@Override
public void visit(Tree.MethodDeclaration that) {
super.visit(that);
Tree.SpecifierExpression sie = that.getSpecifierExpression();
Function dec = that.getDeclarationModel();
if (isInitializerParameter(dec)) {
if (sie != null) {
sie.addError("function is an initializer parameter and may not have an initial value: '" + dec.getName() + "'");
}
}
// unnecessary, let definite assignment checking handle it!
// if (sie==null && isNativeImplementation(dec)) {
// that.addError("missing body for native function: '" +
// dec.getName() + "' must have a body");
// }
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class TypeVisitor method visit.
@Override
public void visit(Tree.MethodDefinition that) {
super.visit(that);
Function dec = that.getDeclarationModel();
if (isInitializerParameter(dec)) {
that.getBlock().addError("function is an initializer parameter and may not have a body: '" + dec.getName() + "'");
}
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class AnnotationVisitor method visit.
@Override
public void visit(Tree.AnyMethod that) {
super.visit(that);
Function a = that.getDeclarationModel();
if (a.isAnnotation()) {
checkAnnotationConstructor(that, a);
}
TypedDeclaration m = that.getDeclarationModel();
Unit unit = that.getUnit();
checkAnnotations(that.getAnnotationList(), unit.getFunctionDeclarationType(), unit.getFunctionMetatype(m.getTypedReference()), that);
}
Aggregations