summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2006-05-18 16:24:52 +0000
committerMartin Odersky <odersky@gmail.com>2006-05-18 16:24:52 +0000
commit63c4d302527a40f92750f2275222ae96b0e72472 (patch)
tree4e4c983f0dbe449ad0d03dc8e6fa86784e6af649
parentf60573811d50b020a2f81e0fb37447b763eb1dd5 (diff)
downloadscala-63c4d302527a40f92750f2275222ae96b0e72472.tar.gz
scala-63c4d302527a40f92750f2275222ae96b0e72472.tar.bz2
scala-63c4d302527a40f92750f2275222ae96b0e72472.zip
Fixed bug 595,596,597
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala2
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala13
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala32
-rwxr-xr-xtest/files/pos/bug595.scala5
-rwxr-xr-xtest/files/pos/bug596.scala7
-rw-r--r--test/files/resident/bug597/Main.scala10
-rw-r--r--test/files/resident/bug597/Test.scala27
-rw-r--r--test/files/resident/bug597/what-happened.txt10
9 files changed, 90 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index d0e3653e21..3466af4f00 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -944,6 +944,8 @@ trait Symbols requires SymbolTable {
tp match { //debug
case TypeRef(_, sym, _) =>
assert(sym != this, this);
+ case ClassInfoType(parents, _, _) =>
+ for(val p <- parents) assert(p.symbol != this, owner)
case _ =>
}
super.setInfo(tp);
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index 18b6cd0a01..cc886f6e79 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -973,7 +973,7 @@ trait Types requires SymbolTable {
/** Rebind symbol `sym' to an overriding member in type `pre' */
private def rebind(pre: Type, sym: Symbol): Symbol = {
val owner = sym.owner;
- if (owner.isClass && owner != pre.symbol && !sym.isFinal) {
+ if (owner.isClass && owner != pre.symbol && !sym.isFinal && !sym.isClass) {
val rebind = pre.nonPrivateMember(sym.name).suchThat(sym => sym.isType || sym.isStable);
if (rebind == NoSymbol) sym else rebind
} else sym
@@ -1409,10 +1409,17 @@ trait Types requires SymbolTable {
if (sym.isModuleClass && !phase.flatClasses) adaptToNewRun(pre, sym.sourceModule).moduleClass;
else if ((pre eq NoPrefix) || (pre eq NoType) || sym.owner.isPackageClass) sym
else {
- val rebind0 = pre.member(sym.name)
+ var rebind0 = pre.member(sym.name)
+ if (sym.owner.name != rebind0.owner.name) {
+ if (settings.debug.value) Console.println("ADAPT1 pre = "+pre+", sym = "+sym+sym.locationString+", rebind = "+rebind0+rebind0.locationString)
+ val bcs = pre.baseClasses.dropWhile(bc => bc.name != sym.owner.name);
+ assert(!bcs.isEmpty)
+ rebind0 = pre.baseType(bcs.head).member(sym.name)
+ if (settings.debug.value) Console.println("ADAPT2 pre = "+pre+", sym = "+sym+sym.locationString+", rebind = "+rebind0+rebind0.locationString)
+ }
val rebind = rebind0.suchThat(sym => sym.isType || sym.isStable)
if (rebind == NoSymbol) {
- System.out.println("" + phase + " " + phase.flatClasses+sym.owner+sym.name)
+ if (settings.debug.value) Console.println("" + phase + " " + phase.flatClasses+sym.owner+sym.name)//debug
throw new MalformedType(pre, sym.name.toString())
}
rebind
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 259e5e248e..2903cfc6bb 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -243,7 +243,7 @@ trait Contexts requires Analyzer {
/** Is `clazz' a subclass of an enclosing class? */
def isSubClassOfEnclosing(clazz: Symbol): boolean = {
- var c = this;
+ var c = this.enclClass;
while (c != NoContext && !clazz.isSubClass(c.owner)) c = c.outer.enclClass;
c != NoContext;
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 68d569bfae..0f88b0e96f 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -124,20 +124,24 @@ trait Typers requires Analyzer {
/** Report a type error.
* @param pos The position where to report the error
* @param ex The exception that caused the error */
- def reportTypeError(pos: int, ex: TypeError): unit = ex match {
- case CyclicReference(sym, info: TypeCompleter) =>
- context.unit.error(pos,
- info.tree match {
- case ValDef(_, _, tpt, _) if (tpt.tpe == null) =>
- "recursive "+sym+" needs type"
- case DefDef(_, _, _, _, tpt, _) if (tpt.tpe == null) =>
- (if (sym.owner.isClass && sym.owner.info.member(sym.name).hasFlag(OVERLOADED)) "overloaded "
- else "recursive ")+sym+" needs result type"
- case _ =>
- ex.getMessage()
- })
- case _ =>
- context.error(pos, ex.getMessage())
+ def reportTypeError(pos: int, ex: TypeError): unit = {
+ if (settings.debug.value) ex.printStackTrace()
+ ex match {
+ case CyclicReference(sym, info: TypeCompleter) =>
+ context.unit.error(
+ pos,
+ info.tree match {
+ case ValDef(_, _, tpt, _) if (tpt.tpe == null) =>
+ "recursive "+sym+" needs type"
+ case DefDef(_, _, _, _, tpt, _) if (tpt.tpe == null) =>
+ (if (sym.owner.isClass && sym.owner.info.member(sym.name).hasFlag(OVERLOADED)) "overloaded "
+ else "recursive ")+sym+" needs result type"
+ case _ =>
+ ex.getMessage()
+ })
+ case _ =>
+ context.error(pos, ex.getMessage())
+ }
}
/** Check that tree is a stable expression.
diff --git a/test/files/pos/bug595.scala b/test/files/pos/bug595.scala
new file mode 100755
index 0000000000..44124c90c9
--- /dev/null
+++ b/test/files/pos/bug595.scala
@@ -0,0 +1,5 @@
+package lampion.scala;
+import _root_.scala.collection._
+
+class Foo extends mutable.HashMap
+
diff --git a/test/files/pos/bug596.scala b/test/files/pos/bug596.scala
new file mode 100755
index 0000000000..b1b5471b2f
--- /dev/null
+++ b/test/files/pos/bug596.scala
@@ -0,0 +1,7 @@
+trait T1 {
+ protected abstract class C
+}
+
+trait T2 extends T1 {
+ class D extends C
+}
diff --git a/test/files/resident/bug597/Main.scala b/test/files/resident/bug597/Main.scala
new file mode 100644
index 0000000000..24d1327135
--- /dev/null
+++ b/test/files/resident/bug597/Main.scala
@@ -0,0 +1,10 @@
+package test;
+
+object Main {
+ def main(args : Array[String]) : Unit = {
+ new ExtC {
+ type A = Ax;
+ class Ax extends super.Ax;
+ }
+ }
+}
diff --git a/test/files/resident/bug597/Test.scala b/test/files/resident/bug597/Test.scala
new file mode 100644
index 0000000000..2f63f46c3d
--- /dev/null
+++ b/test/files/resident/bug597/Test.scala
@@ -0,0 +1,27 @@
+package test;
+
+abstract class Base {
+ type A <: Ax;
+
+ abstract class Ax {
+ def a = null;
+ def string = "A";
+ }
+}
+trait ExtB extends Base {
+ type A <: Ax;
+ trait Ax extends super.Ax {
+ def c = null;
+ override def string = super.string + "C";
+ }
+}
+
+trait ExtC extends /*ExtA with*/ ExtB {
+ type A <: Ax;
+ trait Ax extends super.Ax {
+ a
+ c
+ def d = null;
+ override def string = super.string + "D";
+ }
+}
diff --git a/test/files/resident/bug597/what-happened.txt b/test/files/resident/bug597/what-happened.txt
new file mode 100644
index 0000000000..52e67eda9c
--- /dev/null
+++ b/test/files/resident/bug597/what-happened.txt
@@ -0,0 +1,10 @@
+Run in resident:
+
+bash-3.00$ ~/runtime-workspace/scala/dists/latest/bin/scalac -resident -d ../bin -sourcepath .
+
+nsc> test/Test.scala
+
+nsc> test/Main.scala
+Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
+
+I think there is a recursive function gone crazy somewhere.