Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit c9861cd

Browse files
committed
refinement of sbaz fix; fixed scala#419
1 parent a3dcb88 commit c9861cd

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

src/compiler/scala/tools/nsc/CompilationUnits.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package scala.tools.nsc
88

99
import scala.tools.nsc.util.{FreshNameCreator,OffsetPosition,Position,SourceFile}
1010
import scala.tools.nsc.io.AbstractFile
11-
import scala.collection.mutable.HashSet
11+
import scala.collection.mutable.{HashSet, HashMap}
1212

1313
trait CompilationUnits { self: Global =>
1414

@@ -27,6 +27,10 @@ trait CompilationUnits { self: Global =>
2727
*/
2828
val depends = new HashSet[Symbol]
2929

30+
/** Synthetic definitions generated by namer, eliminated by typer.
31+
*/
32+
val synthetics = new HashMap[Symbol, Tree]
33+
3034
/** used to track changes in a signature */
3135
var pickleHash : Long = 0
3236

src/compiler/scala/tools/nsc/symtab/Symbols.scala

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,12 +861,27 @@ trait Symbols {
861861
if (isClass) this else moduleClass
862862
} else owner.toplevelClass
863863

864+
/** Is this symbol defined in the same scope and compilation unit as `that' symbol?
865+
*/
866+
def isCoDefinedWith(that: Symbol) =
867+
(this.rawInfo ne NoType) && {
868+
val res =
869+
!this.owner.isPackageClass ||
870+
(this.sourceFile eq null) ||
871+
(that.sourceFile eq null) ||
872+
(this.sourceFile eq that.sourceFile)
873+
if (!res) {
874+
println("strange linked: "+this+" "+this.locationString+";"+this.sourceFile+"/"+that+that.locationString+";"+that.sourceFile+";"+that.moduleClass.sourceFile)
875+
}
876+
res
877+
}
878+
864879
/** The class with the same name in the same package as this module or
865880
* case class factory
866881
*/
867882
final def linkedClassOfModule: Symbol = {
868883
if (this != NoSymbol)
869-
owner.info.decl(name.toTypeName).suchThat(sym => sym.rawInfo ne NoType)
884+
owner.info.decl(name.toTypeName).suchThat(_ isCoDefinedWith this)
870885
else NoSymbol
871886
}
872887

@@ -876,15 +891,15 @@ trait Symbols {
876891
final def linkedModuleOfClass: Symbol =
877892
if (this.isClass && !this.isAnonymousClass && !this.isRefinementClass) {
878893
owner.rawInfo.decl(name.toTermName).suchThat(
879-
sym => (sym hasFlag MODULE) && (sym.rawInfo ne NoType))
894+
sym => (sym hasFlag MODULE) && (sym isCoDefinedWith this))
880895
} else NoSymbol
881896

882897
/** For a module its linked class, for a class its linked module or case
883898
* factory otherwise.
884899
*/
885900
final def linkedSym: Symbol =
886901
if (isTerm) linkedClassOfModule
887-
else if (isClass) owner.info.decl(name.toTermName).suchThat(sym => sym.rawInfo ne NoType)
902+
else if (isClass) owner.info.decl(name.toTermName).suchThat(_ isCoDefinedWith this)
888903
else NoSymbol
889904

890905
/** For a module class its linked class, for a plain class

src/compiler/scala/tools/nsc/typechecker/Namers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ trait Namers { self: Analyzer =>
230230
(!currentRun.compiles(m) || (m hasFlag SYNTHETIC))) {
231231
updatePosFlags(m, tree.pos, moduleFlags)
232232
setPrivateWithin(tree, m, tree.mods)
233-
synthetics -= m
233+
context.unit.synthetics -= m
234234
} else {
235235
m = context.owner.newModule(tree.pos, tree.name)
236236
m.setFlag(moduleFlags)
@@ -392,7 +392,7 @@ trait Namers { self: Analyzer =>
392392

393393
def enterSyntheticSym(tree: Tree): Symbol = {
394394
enterSym(tree)
395-
synthetics(tree.symbol) = (tree, context.unit.source)
395+
context.unit.synthetics(tree.symbol) = tree
396396
tree.symbol
397397
}
398398

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,11 @@ trait Typers { self: Analyzer =>
3838

3939
private val superDefs = new HashMap[Symbol, ListBuffer[Tree]]
4040

41-
val synthetics = new HashMap[Symbol, (Tree, SourceFile)]
42-
4341
def resetTyper() {
4442
resetContexts
4543
resetNamer()
4644
transformed.clear
4745
superDefs.clear
48-
synthetics.clear
4946
}
5047

5148
object UnTyper extends Traverser {
@@ -1548,10 +1545,10 @@ trait Typers { self: Analyzer =>
15481545
}
15491546

15501547
// add synthetics
1551-
synthetics get e.sym match {
1552-
case Some((tree, source)) if (source eq context.unit.source) =>
1548+
context.unit.synthetics get e.sym match {
1549+
case Some(tree) =>
15531550
newStats += tree
1554-
synthetics -= e.sym
1551+
context.unit.synthetics -= e.sym
15551552
case _ =>
15561553
}
15571554

0 commit comments

Comments
 (0)