From 63c4d302527a40f92750f2275222ae96b0e72472 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 18 May 2006 16:24:52 +0000 Subject: Fixed bug 595,596,597 --- src/compiler/scala/tools/nsc/symtab/Symbols.scala | 2 ++ src/compiler/scala/tools/nsc/symtab/Types.scala | 13 +++++++-- .../scala/tools/nsc/typechecker/Contexts.scala | 2 +- .../scala/tools/nsc/typechecker/Typers.scala | 32 ++++++++++++---------- 4 files changed, 31 insertions(+), 18 deletions(-) (limited to 'src') 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. -- cgit v1.2.3