diff options
author | Martin Odersky <odersky@gmail.com> | 2008-02-12 15:25:38 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2008-02-12 15:25:38 +0000 |
commit | c9861cd1980642e299c7fefa496878bcc573d7a8 (patch) | |
tree | 9ee21ce87a05ad8d379f0581d48cab62c902f93b /src/compiler | |
parent | a3dcb88cada2394337db422d9662bff97adb968c (diff) | |
download | scala-c9861cd1980642e299c7fefa496878bcc573d7a8.tar.gz scala-c9861cd1980642e299c7fefa496878bcc573d7a8.tar.bz2 scala-c9861cd1980642e299c7fefa496878bcc573d7a8.zip |
refinement of sbaz fix; fixed #419
Diffstat (limited to 'src/compiler')
4 files changed, 28 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala index c7d4f84b45..68f5793a8b 100644 --- a/src/compiler/scala/tools/nsc/CompilationUnits.scala +++ b/src/compiler/scala/tools/nsc/CompilationUnits.scala @@ -8,7 +8,7 @@ package scala.tools.nsc import scala.tools.nsc.util.{FreshNameCreator,OffsetPosition,Position,SourceFile} import scala.tools.nsc.io.AbstractFile -import scala.collection.mutable.HashSet +import scala.collection.mutable.{HashSet, HashMap} trait CompilationUnits { self: Global => @@ -27,6 +27,10 @@ trait CompilationUnits { self: Global => */ val depends = new HashSet[Symbol] + /** Synthetic definitions generated by namer, eliminated by typer. + */ + val synthetics = new HashMap[Symbol, Tree] + /** used to track changes in a signature */ var pickleHash : Long = 0 diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 03ea3c0b5a..3208ea16b0 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -861,12 +861,27 @@ trait Symbols { if (isClass) this else moduleClass } else owner.toplevelClass + /** Is this symbol defined in the same scope and compilation unit as `that' symbol? + */ + def isCoDefinedWith(that: Symbol) = + (this.rawInfo ne NoType) && { + val res = + !this.owner.isPackageClass || + (this.sourceFile eq null) || + (that.sourceFile eq null) || + (this.sourceFile eq that.sourceFile) + if (!res) { + println("strange linked: "+this+" "+this.locationString+";"+this.sourceFile+"/"+that+that.locationString+";"+that.sourceFile+";"+that.moduleClass.sourceFile) + } + res + } + /** The class with the same name in the same package as this module or * case class factory */ final def linkedClassOfModule: Symbol = { if (this != NoSymbol) - owner.info.decl(name.toTypeName).suchThat(sym => sym.rawInfo ne NoType) + owner.info.decl(name.toTypeName).suchThat(_ isCoDefinedWith this) else NoSymbol } @@ -876,7 +891,7 @@ trait Symbols { final def linkedModuleOfClass: Symbol = if (this.isClass && !this.isAnonymousClass && !this.isRefinementClass) { owner.rawInfo.decl(name.toTermName).suchThat( - sym => (sym hasFlag MODULE) && (sym.rawInfo ne NoType)) + sym => (sym hasFlag MODULE) && (sym isCoDefinedWith this)) } else NoSymbol /** For a module its linked class, for a class its linked module or case @@ -884,7 +899,7 @@ trait Symbols { */ final def linkedSym: Symbol = if (isTerm) linkedClassOfModule - else if (isClass) owner.info.decl(name.toTermName).suchThat(sym => sym.rawInfo ne NoType) + else if (isClass) owner.info.decl(name.toTermName).suchThat(_ isCoDefinedWith this) else NoSymbol /** For a module class its linked class, for a plain class diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 34ba460f90..a4f70e7c15 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -230,7 +230,7 @@ trait Namers { self: Analyzer => (!currentRun.compiles(m) || (m hasFlag SYNTHETIC))) { updatePosFlags(m, tree.pos, moduleFlags) setPrivateWithin(tree, m, tree.mods) - synthetics -= m + context.unit.synthetics -= m } else { m = context.owner.newModule(tree.pos, tree.name) m.setFlag(moduleFlags) @@ -392,7 +392,7 @@ trait Namers { self: Analyzer => def enterSyntheticSym(tree: Tree): Symbol = { enterSym(tree) - synthetics(tree.symbol) = (tree, context.unit.source) + context.unit.synthetics(tree.symbol) = tree tree.symbol } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 1586093c76..806698dd65 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -38,14 +38,11 @@ trait Typers { self: Analyzer => private val superDefs = new HashMap[Symbol, ListBuffer[Tree]] - val synthetics = new HashMap[Symbol, (Tree, SourceFile)] - def resetTyper() { resetContexts resetNamer() transformed.clear superDefs.clear - synthetics.clear } object UnTyper extends Traverser { @@ -1548,10 +1545,10 @@ trait Typers { self: Analyzer => } // add synthetics - synthetics get e.sym match { - case Some((tree, source)) if (source eq context.unit.source) => + context.unit.synthetics get e.sym match { + case Some(tree) => newStats += tree - synthetics -= e.sym + context.unit.synthetics -= e.sym case _ => } |