summaryrefslogtreecommitdiff
path: root/sources/scalac/typechecker
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-09-07 17:54:44 +0000
committerMartin Odersky <odersky@gmail.com>2003-09-07 17:54:44 +0000
commit70d78cbfc802ccc49d5d324755865ff07985dfef (patch)
treebc524a99cc8d3f6a5a722a60d98aacbd06f9c92b /sources/scalac/typechecker
parent43c5c82eb9ee00e7d87042a1195d854f4ac79df3 (diff)
downloadscala-70d78cbfc802ccc49d5d324755865ff07985dfef.tar.gz
scala-70d78cbfc802ccc49d5d324755865ff07985dfef.tar.bz2
scala-70d78cbfc802ccc49d5d324755865ff07985dfef.zip
*** empty log message ***
Diffstat (limited to 'sources/scalac/typechecker')
-rw-r--r--sources/scalac/typechecker/Analyzer.java26
-rw-r--r--sources/scalac/typechecker/Infer.java21
-rw-r--r--sources/scalac/typechecker/RefCheck.java60
3 files changed, 53 insertions, 54 deletions
diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java
index 55da4c5f88..fc53218f5e 100644
--- a/sources/scalac/typechecker/Analyzer.java
+++ b/sources/scalac/typechecker/Analyzer.java
@@ -369,7 +369,8 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
if ((bsym.flags & FINAL) != 0) {
error(constrs[i].pos, "illegal inheritance from final class");
} else if (bsym.isSealed() ||
- bsym.isSubClass(definitions.ANYVAL_CLASS)) {
+ bsym.isSubClass(definitions.ANYVAL_CLASS) ||
+ bsym.isSubClass(definitions.ARRAY_CLASS)) {
// are we in same scope as base type definition?
Scope.Entry e = context.scope.lookupEntry(bsym.name);
if (e.sym != bsym || e.owner != context.scope) {
@@ -859,7 +860,10 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
}
context.scope.unlink(e);
context.scope.enter(sym);
- } else if (sym.kind == VAL && other.kind == VAL) {
+ } else if (context.owner.kind == CLASS &&
+ sym.kind == VAL && other.kind == VAL &&
+ ((sym.flags & ACCESSOR) == 0 ||
+ (other.flags & ACCESSOR) == 0)) {
// it's an overloaded definition
/*
if (((sym.flags ^ other.flags) & SOURCEFLAGS) != 0) {
@@ -873,9 +877,14 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
*/
e.setSymbol(other.overloadWith(sym));
} else {
- error(sym.pos,
- sym.nameString() + " is already defined as " +
- other + other.locationString());
+ if (context.owner.kind == CLASS)
+ error(sym.pos,
+ sym.nameString() + " is already defined as " +
+ other + other.locationString());
+ else
+ error(sym.pos,
+ sym.nameString() +
+ " is already defined in local scope");
}
} else {
context.scope.enter(sym);
@@ -2075,7 +2084,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
.isSameAs(sym1.type()))
refinement.enter(sym1);
}
- if (refinement.elems == Scope.Entry.NONE &&
+ if (refinement.isEmpty() &&
parentTypes.length == 1)
owntype = parentTypes[0];
else
@@ -2187,8 +2196,9 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
} else {
// it was an alias type
// todo: handle overloaded constructors
- fn1 = gen.TypeApply(
- fn1, gen.mkTypes(fn1.pos, argtypes));
+ if (argtypes.length != 0)
+ fn1 = gen.TypeApply(
+ fn1, gen.mkTypes(fn1.pos, argtypes));
if (tsym.typeParams().length != 0 &&
!(fn0 instanceof AppliedType))
fn1.type = Type.PolyType(
diff --git a/sources/scalac/typechecker/Infer.java b/sources/scalac/typechecker/Infer.java
index c14515f841..5dcf9bf0db 100644
--- a/sources/scalac/typechecker/Infer.java
+++ b/sources/scalac/typechecker/Infer.java
@@ -65,23 +65,6 @@ public class Infer implements Modifiers, Kinds {
(sym == null ? "expression" : sym) + " of type " + tp;
}
-// Helper definitions ---------------------------------------------------------
-
- /** Is type `tp' a polymorphic method type?
- */
- private boolean isPolymorphic(Type tp) {
- return tp.typeParams().length > 0;
- }
-
- /** Is type `tp' a parameterized method type?
- */
- boolean isParameterized(Type tp) {
- switch (tp) {
- case MethodType(_, _): return true;
- default: return isPolymorphic(tp);
- }
- }
-
// Tree Substitution -------------------------------------------------------------
static class Substituter extends Transformer {
@@ -954,8 +937,8 @@ public class Infer implements Modifiers, Kinds {
}
//where
private boolean improves(Type tp1, Type tp2) {
- return isParameterized(tp2) &&
- (!isParameterized(tp1) || specializes(tp1, tp2));
+ return tp2.isParameterized() &&
+ (!tp1.isParameterized() || specializes(tp1, tp2));
}
/** Assign `tree' the type of an alternative
diff --git a/sources/scalac/typechecker/RefCheck.java b/sources/scalac/typechecker/RefCheck.java
index 24c452cf70..d3a603642a 100644
--- a/sources/scalac/typechecker/RefCheck.java
+++ b/sources/scalac/typechecker/RefCheck.java
@@ -69,14 +69,14 @@ public class RefCheck extends Transformer implements Modifiers, Kinds {
for (Scope.SymbolIterator it = closure[i].members().iterator(true);
it.hasNext();) {
Symbol other = it.next();
- Symbol members = ((other.flags & PRIVATE) != 0) ? other
+ Symbol member = ((other.flags & PRIVATE) != 0) ? other
: clazz.info().lookup(other.name);
- Symbol member = Symbol.NONE;
- if (members.kind != NONE &&
- members.owner() != other.owner() &&
- (members.owner() == clazz ||
- !members.owner().isSubClass(other.owner())))
- member = checkOverride(pos, clazz, members, other);
+ if (member.owner() == other.owner())
+ member = other;
+ else if (member.type() instanceof Type.OverloadedType)
+ member = findOverriding(pos, clazz, member, other);
+ if (member.kind != NONE && member != other)
+ checkOverride(pos, clazz, member, other);
if (clazz.kind == CLASS && (clazz.flags & ABSTRACTCLASS) == 0) {
if ((member.flags & DEFERRED) != 0) {
abstractClassError(
@@ -116,21 +116,7 @@ public class RefCheck extends Transformer implements Modifiers, Kinds {
clazz.flags |= ABSTRACTCLASS;
}
- /** Check that all conditions for overriding `other' by `member' are met.
- * That is for overriding member M and overridden member O:
- *
- * 1. M must have the same or stronger access privileges as O.
- * 2. O must not be final.
- * 3. O is deferred, or M has `override' modifier.
- * 4. O is not a class, nor a class constructor.
- * 5. If O is a type alias, then M is an alias of O.
- * 6. If O is an abstract type then
- * either M is an abstract type, and M's bounds are sharper than O's bounds.
- * or M is a type alias or class which conforms to O's bounds.
- * 7. If O and M are values, then M's type is a subtype of O's type.
- * 8. If O is an immutable value, then so is M.
- */
- Symbol checkOverride(int pos, Symbol clazz, Symbol members, Symbol other) {
+ Symbol findOverriding(int pos, Symbol clazz, Symbol members, Symbol other) {
Type self = clazz.thisType();
Symbol member = members;
Type memberinfo = normalizedInfo(self, member);
@@ -153,10 +139,29 @@ public class RefCheck extends Transformer implements Modifiers, Kinds {
}
}
}
- if (member == members) {
- }
}
- if (member.owner() == clazz) pos = member.pos;
+ return member;
+ }
+
+ /** Check that all conditions for overriding `other' by `member' are met.
+ * That is for overriding member M and overridden member O:
+ *
+ * 1. M must have the same or stronger access privileges as O.
+ * 2. O must not be final.
+ * 3. O is deferred, or M has `override' modifier.
+ * 4. O is not a class, nor a class constructor.
+ * 5. If O is a type alias, then M is an alias of O.
+ * 6. If O is an abstract type then
+ * either M is an abstract type, and M's bounds are sharper than O's bounds.
+ * or M is a type alias or class which conforms to O's bounds.
+ * 7. If O and M are values, then M's type is a subtype of O's type.
+ * 8. If O is an immutable value, then so is M.
+ */
+ void checkOverride(int pos, Symbol clazz, Symbol member, Symbol other) {
+ if (member.owner() == clazz)
+ pos = member.pos;
+ else if (member.owner().isSubClass(other.owner()))
+ return; // everything was already checked elsewhere
if ((member.flags & PRIVATE) != 0) {
overrideError(pos, member, other, "has weaker access privileges; it should not be private");
@@ -177,6 +182,7 @@ public class RefCheck extends Transformer implements Modifiers, Kinds {
":\n both are inherited from mixin classes; " +
"\n an overriding definition in the current template is required");
} else {
+ Type self = clazz.thisType();
switch (other.kind) {
case CLASS:
overrideError(pos, member, other, "cannot override a class");
@@ -189,7 +195,8 @@ public class RefCheck extends Transformer implements Modifiers, Kinds {
if (other.isConstructor())
overrideError(pos, member, other,
"cannot override a class constructor");
- if (!memberinfo.isSubType(otherinfo))
+ if (!normalizedInfo(self, member).isSubType(
+ normalizedInfo(self, other)))
overrideTypeError(pos, member, other, self, false);
if (member.kind == TYPE &&
!self.memberLoBound(other).isSubType(
@@ -198,7 +205,6 @@ public class RefCheck extends Transformer implements Modifiers, Kinds {
}
}
- return member;
}
void overrideError(int pos, Symbol member, Symbol other, String msg) {