summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2004-07-05 11:04:23 +0000
committerMartin Odersky <odersky@gmail.com>2004-07-05 11:04:23 +0000
commit5325bdaaf253bbbed772563563db27b1add96ae1 (patch)
treeeab54d104d38eedff343d2f1c23b36c360120a0b
parent19a0b7bf76d559f4bf0bde0130962df4a47ac0cf (diff)
downloadscala-5325bdaaf253bbbed772563563db27b1add96ae1.tar.gz
scala-5325bdaaf253bbbed772563563db27b1add96ae1.tar.bz2
scala-5325bdaaf253bbbed772563563db27b1add96ae1.zip
*** empty log message ***
-rw-r--r--sources/scala/tools/scalac/typechecker/Infer.scala1
-rw-r--r--sources/scalac/transformer/UnCurry.java47
2 files changed, 26 insertions, 22 deletions
diff --git a/sources/scala/tools/scalac/typechecker/Infer.scala b/sources/scala/tools/scalac/typechecker/Infer.scala
index ae6adbadef..ab18187594 100644
--- a/sources/scala/tools/scalac/typechecker/Infer.scala
+++ b/sources/scala/tools/scalac/typechecker/Infer.scala
@@ -1248,6 +1248,7 @@ class Infer(global: scalac_Global, gen: TreeGen, make: TreeFactory) extends scal
def exprAlternative(tree: Tree, alts: Array[Symbol], alttypes: Array[Type], pt: Type): unit = {
def improves(tp1: Type, tp2: Type): boolean =
+ tp2 == Type.ErrorType ||
!normalize(tp2).isSubType(pt) && normalize(tp1).isSubType(pt) ||
tp2.isParameterized() &&
(!tp1.isParameterized() || specializes(tp1, tp2));
diff --git a/sources/scalac/transformer/UnCurry.java b/sources/scalac/transformer/UnCurry.java
index 0deb9fc3fc..296817bf16 100644
--- a/sources/scalac/transformer/UnCurry.java
+++ b/sources/scalac/transformer/UnCurry.java
@@ -333,48 +333,59 @@ public class UnCurry extends OwnerTransformer
private void checkNoDoubleDef(Symbol clazz, Symbol sym) {
switch (sym.type()) {
case OverloadedType(Symbol[] alts, Type[] alttypes):
- for (int i = 0; i < alttypes.length; i++) {
+ for (int i = 0; i < alttypes.length; i++)
for (int j = i + 1; j < alttypes.length; j++)
- if (inConflict(alts[i], alts[j], descr.uncurry(alttypes[i]), descr.uncurry(alttypes[j])))
- conflictError(clazz, alts[i], alts[j], alttypes[i], alttypes[j]);
- }
+ checkNoDoubleDef(clazz, alts[i], alts[j], alttypes[i], alttypes[j]);
break;
default:
}
}
- private void conflictError(Symbol clazz, Symbol sym1, Symbol sym2, Type type1, Type type2) {
+ private void checkNoDoubleDef(Symbol clazz,
+ Symbol sym1, Symbol sym2,
+ Type type1, Type type2) {
+ Type newtype1 = descr.uncurry(type1);
+ Type newtype2 = descr.uncurry(type2);
+ if (sym1.owner() != sym2.owner() &&
+ (newtype1.overrides(newtype2) || newtype2.overrides(newtype1)))
+ conflictError(clazz, sym1, sym2, type1, type2, "uncurry");
+ else if (erasureConflict(newtype1, newtype2))
+ conflictError(clazz, sym1, sym2, type1, type2, "erasure");
+ }
+
+ private void conflictError(Symbol clazz, Symbol sym1, Symbol sym2,
+ Type type1, Type type2, String phase) {
if (sym1.owner() == clazz && sym2.owner() == clazz)
unit.error(sym2.pos,
"Double declaration:\n" +
sym1 + ": " + type1 + " and\n" +
- sym2 + ": " + type2 + " have same types after erasure");
+ sym2 + ": " + type2 + " have same types after " + phase);
else if (sym1.owner() == clazz)
unit.error(sym1.pos,
"Accidental override:\n" +
- sym1 + ": " + type1 + " has same type after erasure as\n" +
+ sym1 + ": " + type1 + " has same type after " + phase + " as\n" +
sym2 + ": " + type2 + " which is inherited from " + sym2.owner());
else if (sym2.owner() == clazz)
unit.error(sym2.pos,
"Accidental override:\n" +
- sym2 + ": " + type2 + " has same type after erasure as\n" +
+ sym2 + ": " + type2 + " has same type after " + phase + " as\n" +
sym1 + ": " + type1 + " which is inherited from " + sym1.owner());
else
unit.error(clazz.pos,
"Inheritance conflict: inherited members\n" +
sym1 + ": " + type1 + sym1.locationString() + " and\n" +
- sym2 + ": " + type2 + sym2.locationString() + " have same types after erasure");
+ sym2 + ": " + type2 + sym2.locationString() + " have same types after " + phase);
}
- private boolean inConflict(Symbol sym1, Symbol sym2, Type type1, Type type2) {
+ private boolean erasureConflict(Type type1, Type type2) {
switch (type1) {
case PolyType(_, Type restype1):
- return inConflict(sym1, sym2, restype1, type2);
+ return erasureConflict(restype1, type2);
case MethodType(Symbol[] params1, Type restype1):
switch (type2) {
case PolyType(_, Type restype2):
- return inConflict(sym1, sym2, type1, restype2);
+ return erasureConflict(type1, restype2);
case MethodType(Symbol[] params2, Type restype2):
if (params1.length != params2.length) return false;
@@ -382,15 +393,7 @@ public class UnCurry extends OwnerTransformer
if (!params1[i].nextInfo().erasure().isSameAs(
params2[i].nextInfo().erasure())) return false;
}
- if (restype1.erasure().isSameAs(restype2.erasure()))
- return true;
- if (sym1.owner() == sym2.owner())
- return false;
- for (int i = 0; i < params1.length; i++) {
- if (!params1[i].nextInfo().isSameAs(
- params2[i].nextInfo())) return false;
- }
- return true;
+ return restype1.erasure().isSameAs(restype2.erasure());
default:
return false;
@@ -399,7 +402,7 @@ public class UnCurry extends OwnerTransformer
default:
switch (type2) {
case PolyType(_, _):
- case MethodType(_, _): return inConflict(sym1, sym2, type2, type1);
+ case MethodType(_, _): return erasureConflict(type2, type1);
default: return true;
}
}