use of org.eclipse.ceylon.model.typechecker.model.Unit in project ceylon by eclipse.
the class RefinementVisitor method checkOverloadedParameters.
private void checkOverloadedParameters(Tree.Declaration that, Declaration member) {
String name = member.getName();
Declaration abstraction = member.getScope().getDirectMember(name, null, false);
if (abstraction != null) {
Functional fun = (Functional) member;
List<Parameter> parameters = fun.getFirstParameterList().getParameters();
for (Parameter param : parameters) {
if (param.isDefaulted()) {
that.addError("overloaded function parameter must be required: parameter '" + param.getName() + "' is defaulted");
}
}
Unit unit = that.getUnit();
for (Declaration dec : abstraction.getOverloads()) {
if (dec == member)
break;
Functional other = (Functional) dec;
List<Parameter> otherParams = other.getFirstParameterList().getParameters();
if (otherParams.size() == parameters.size()) {
boolean allSame = true;
for (int i = 0; i < parameters.size(); i++) {
TypeDeclaration paramType = erasedType(parameters.get(i), unit);
TypeDeclaration otherType = erasedType(otherParams.get(i), unit);
if (paramType != null && otherType != null && !paramType.equals(otherType)) {
allSame = false;
break;
}
}
if (allSame) {
that.addError("non-unique parameter list erasure for overloaded function: each overloaded declaration of '" + name + "' must have a distinct parameter list erasure");
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Unit in project ceylon by eclipse.
the class RefinementVisitor method visit.
@Override
public void visit(Tree.SpecifierStatement that) {
super.visit(that);
List<Type> sig = new ArrayList<Type>();
Tree.Term term = that.getBaseMemberExpression();
while (term instanceof Tree.ParameterizedExpression) {
sig.clear();
Tree.ParameterizedExpression pe = (Tree.ParameterizedExpression) term;
Tree.TypeParameterList typeParameterList = pe.getTypeParameterList();
if (typeParameterList != null) {
// TODO: remove this for #1329
typeParameterList.addError("specification statements may not have type parameters");
}
Tree.ParameterList pl = pe.getParameterLists().get(0);
for (Tree.Parameter p : pl.getParameters()) {
if (p == null) {
sig.add(null);
} else {
Parameter model = p.getParameterModel();
if (model != null) {
sig.add(model.getType());
} else {
sig.add(null);
}
}
}
term = pe.getPrimary();
}
if (term instanceof Tree.BaseMemberExpression) {
Tree.BaseMemberExpression bme = (Tree.BaseMemberExpression) term;
Unit unit = that.getUnit();
TypedDeclaration td = getTypedDeclaration(bme.getScope(), name(bme.getIdentifier()), sig, false, unit);
if (td != null) {
that.setDeclaration(td);
Scope scope = that.getScope();
Scope container = scope.getContainer();
Scope realScope = getRealScope(container);
if (realScope instanceof ClassOrInterface) {
ClassOrInterface ci = (ClassOrInterface) realScope;
Scope tdcontainer = td.getContainer();
if (td.isClassOrInterfaceMember()) {
ClassOrInterface tdci = (ClassOrInterface) tdcontainer;
if (!tdcontainer.equals(realScope) && ci.inherits(tdci)) {
boolean lazy = that.getSpecifierExpression() instanceof Tree.LazySpecifierExpression;
if (!lazy && td.isVariable() && td.isJava()) {
// allow assignment to variable
// member of Java supertype
} else // refinement of an inherited member
if (tdcontainer == scope) {
that.addError("parameter declaration hides refining member: '" + td.getName(unit) + "' (rename parameter)");
} else if (td instanceof Value) {
refineAttribute((Value) td, bme, that, ci);
} else if (td instanceof Function) {
refineMethod((Function) td, bme, that, ci);
} else {
// TODO!
bme.addError("not a reference to a formal attribute: '" + td.getName(unit) + "'");
}
}
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Unit in project ceylon by eclipse.
the class SupertypeVisitor method checkForUndecidability.
private void checkForUndecidability(Tree.ExtendedType etn, Tree.SatisfiedTypes stn, TypeDeclaration type, Tree.TypeDeclaration that) {
boolean errors = false;
if (stn != null) {
for (Tree.StaticType st : stn.getTypes()) {
Type t = st.getTypeModel();
if (t != null) {
TypeDeclaration td = t.getDeclaration();
if (!(td instanceof UnknownType) && !(td instanceof TypeAlias)) {
if (td == type) {
brokenSatisfiedType(type, st, null);
errors = true;
} else {
List<TypeDeclaration> list = t.isRecursiveRawTypeDefinition(singleton(type));
if (!list.isEmpty()) {
brokenSatisfiedType(type, st, list);
errors = true;
}
}
}
}
}
}
if (etn != null) {
Tree.StaticType et = etn.getType();
if (et != null) {
Type t = et.getTypeModel();
if (t != null) {
TypeDeclaration td = t.getDeclaration();
if (!(td instanceof UnknownType) && !(td instanceof TypeAlias)) {
if (td == type) {
brokenExtendedType(type, et, null);
errors = true;
} else {
List<TypeDeclaration> list = t.isRecursiveRawTypeDefinition(singleton(type));
if (!list.isEmpty()) {
brokenExtendedType(type, et, list);
errors = true;
}
}
}
}
}
}
if (!errors) {
Unit unit = type.getUnit();
List<Type> list = new ArrayList<Type>();
try {
List<Type> supertypes = type.getType().getSupertypes();
for (Type st : supertypes) {
addToIntersection(list, st, unit);
}
// probably unnecessary - if it were
// going to blow up, it would have
// already blown up in addToIntersection()
canonicalIntersection(list, unit);
} catch (DecidabilityException re) {
brokenHierarchy(type, that, unit);
return;
}
try {
type.getType().getUnionOfCases();
} catch (DecidabilityException re) {
brokenSelfType(type, that);
}
if (stn != null) {
for (Tree.StaticType st : stn.getTypes()) {
Type t = st.getTypeModel();
if (t != null) {
if (checkSupertypeVariance(t, type, st)) {
type.getSatisfiedTypes().remove(t);
type.clearProducedTypeCache();
}
}
}
}
if (etn != null) {
Tree.StaticType et = etn.getType();
if (et != null) {
Type t = et.getTypeModel();
if (t != null) {
if (checkSupertypeVariance(t, type, et)) {
type.setExtendedType(unit.getBasicType());
type.clearProducedTypeCache();
}
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Unit in project ceylon by eclipse.
the class SupertypeVisitor method checkSupertypeVariance.
private boolean checkSupertypeVariance(Type type, TypeDeclaration d, Node node) {
List<TypeDeclaration> errors = type.resolveAliases().checkDecidability();
if (displayErrors) {
for (TypeDeclaration td : errors) {
Unit unit = node.getUnit();
node.addError("type with contravariant type parameter '" + td.getName() + "' appears in contravariant or invariant location in supertype: '" + type.asString(unit) + "'");
}
}
return !errors.isEmpty();
}
use of org.eclipse.ceylon.model.typechecker.model.Unit in project ceylon by eclipse.
the class ImportVisitor method checkForHiddenToplevel.
private boolean checkForHiddenToplevel(Tree.Identifier id, Import i, Tree.Alias alias, ImportList il) {
ImportScope scope = getImportScope(il);
for (Declaration d : scope.getMembers()) {
String n = d.getName();
Declaration idec = i.getDeclaration();
if (n != null && i.getAlias().equals(n) && !idec.equals(d) && // alias:
!isLegalAliasFreeImport(d, idec)) {
String qn = d.getQualifiedNameString();
String message = scope instanceof Unit ? "toplevel declaration with this name declared in this unit" : "declaration with this name declared in this scope";
if (alias == null) {
String iqn = idec.getQualifiedNameString();
id.addError(message + ": imported '" + iqn + "' would hide '" + qn + "' (add an alias to the import)");
} else {
alias.addError(message + ": imported '" + n + "' would hide '" + qn + "' (choose a different alias for the import)");
}
return true;
}
}
return false;
}
Aggregations