diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 19 | ||||
-rw-r--r-- | test/files/run/t1987.check | 16 | ||||
-rw-r--r-- | test/files/run/t1987.flags | 1 | ||||
-rw-r--r-- | test/files/run/t1987.scala | 62 |
4 files changed, 97 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 6476244221..9bb8b1ea8b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3804,7 +3804,24 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { pre = cx.enclClass.prefix defEntry = cx.scope.lookupEntry(name) if ((defEntry ne null) && qualifies(defEntry.sym)) { - defSym = defEntry.sym + // Right here is where SI-1987, overloading in package objects, can be + // seen to go wrong. There is an overloaded symbol, but when referring + // to the unqualified identifier from elsewhere in the package, only + // the last definition is visible. So overloading mis-resolves and is + // definition-order dependent, bad things. See run/t1987.scala. + // + // I assume the actual problem involves how/where these symbols are entered + // into the scope. But since I didn't figure out how to fix it that way, I + // catch it here by looking up package-object-defined symbols in the prefix. + if (isInPackageObject(defEntry.sym, pre.typeSymbol)) { + defSym = pre.member(defEntry.sym.name) + if (defSym ne defEntry.sym) { + log("!!! Overloaded package object member resolved incorrectly.\n Discarded: " + + defEntry.sym.defString + "\n Using: " + defSym.defString) + } + } + else + defSym = defEntry.sym } else { cx = cx.enclClass diff --git a/test/files/run/t1987.check b/test/files/run/t1987.check new file mode 100644 index 0000000000..d2102a4a18 --- /dev/null +++ b/test/files/run/t1987.check @@ -0,0 +1,16 @@ +long +long +double +double +long +long +double +double +long +long +double +double +long +long +double +double diff --git a/test/files/run/t1987.flags b/test/files/run/t1987.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/files/run/t1987.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/test/files/run/t1987.scala b/test/files/run/t1987.scala new file mode 100644 index 0000000000..4c278ec6a0 --- /dev/null +++ b/test/files/run/t1987.scala @@ -0,0 +1,62 @@ +// a.scala +// Fri Jan 13 11:31:47 PST 2012 + +package foo { + package object bar { + def duh(n: Long) = println("long") + def duh(n: Double) = println("double") + + def duh2(n: Double) = println("double") + def duh2(n: Long) = println("long") + } + package bar { + object Main { + def main(args:Array[String]) { + duh(33L) + bip.bar.duh(33L) + duh(33d) + bip.bar.duh(33d) + + duh2(33L) + bip.bar.duh2(33L) + duh2(33d) + bip.bar.duh2(33d) + } + } + } +} + +package bip { + trait Duh { + def duh(n: Long) = println("long") + def duh(n: Double) = println("double") + } + trait Duh2 { + def duh2(n: Double) = println("double") + def duh2(n: Long) = println("long") + } + + package object bar extends Duh with Duh2 { } + package bar { + object Main { + def main(args:Array[String]) { + duh(33L) + bip.bar.duh(33L) + duh(33d) + bip.bar.duh(33d) + + duh2(33L) + bip.bar.duh2(33L) + duh2(33d) + bip.bar.duh2(33d) + } + } + } +} + +object Test { + def main(args: Array[String]): Unit = { + foo.bar.Main.main(null) + bip.bar.Main.main(null) + } +} |