diff options
author | Paul Phillips <paulp@improving.org> | 2012-01-13 13:32:56 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-01-13 13:48:12 -0800 |
commit | 66a3623d59a261830076c7ad2b04fbb82e415547 (patch) | |
tree | 8e1d0ca2ae15e6b753b2c8c47ddcaac48ec1dd86 /src | |
parent | b0de5f13329aa24752fae079c50cc0584471379e (diff) | |
download | scala-66a3623d59a261830076c7ad2b04fbb82e415547.tar.gz scala-66a3623d59a261830076c7ad2b04fbb82e415547.tar.bz2 scala-66a3623d59a261830076c7ad2b04fbb82e415547.zip |
Fixed overloading in package objects.
Implementing a warning for the behavior described in SI-1987 gave me
enough of a foot in the door to fix it rather than warning about it. I
suppose this is a variation of rubber ducky debugging.
% scalac -Ylog:typer test/files/run/t1987.scala
[log typer] !!! Overloaded package object member resolved incorrectly.
Discarded: def duh(n: Double): Unit
Using: val duh: (n: Double)Unit <and> (n: Long)Unit
Review by @odersky.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 19 |
1 files changed, 18 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 |