diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/Settings.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala | 19 | ||||
-rw-r--r-- | test/files/pos/t1745/J.java (renamed from test/pending/pos/t1745/J.java) | 0 | ||||
-rw-r--r-- | test/files/pos/t1745/S.scala (renamed from test/pending/pos/t1745/S.scala) | 0 | ||||
-rw-r--r-- | test/files/run/bug363.check (renamed from test/pending/run/bug363.check) | 0 | ||||
-rw-r--r-- | test/files/run/bug363.scala (renamed from test/pending/run/bug363.scala) | 0 |
6 files changed, 12 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala index c0b26ff620..f788151aef 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -734,7 +734,7 @@ trait ScalacSettings { val checkInit = BooleanSetting ("-Xcheckinit", "Add runtime checks on field accessors. Uninitialized accesses result in an exception being thrown.") val noassertions = BooleanSetting ("-Xdisable-assertions", "Generate no assertions and assumptions") val Xexperimental = BooleanSetting ("-Xexperimental", "Enable experimental extensions") - val forwarders = BooleanSetting ("-Xforwarders", "Generate static forwarders in mirror classes") + val noForwarders = BooleanSetting ("-Xno-forwarders", "Do not generate static forwarders in mirror classes") val future = BooleanSetting ("-Xfuture", "Turn on future language features") val genPhaseGraph = StringSetting ("-Xgenerate-phase-graph", "file", "Generate the phase graphs (outputs .dot files) to fileX.dot", "") val XlogImplicits = BooleanSetting ("-Xlog-implicits", "Show more info on why some implicits are not applicable") diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index 9097b8b6b1..dcecbcbf80 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -202,18 +202,19 @@ abstract class GenJVM extends SubComponent { } } else { + // it must be a top level class (name contains no $s) + def isCandidateForForwarders(sym: Symbol): Boolean = + atPhase (currentRun.picklerPhase.next) { + !(sym.name.toString contains '$') && (sym hasFlag Flags.MODULE) && !sym.isImplClass && !sym.isNestedClass + } + val lmoc = c.symbol.linkedModuleOfClass // add static forwarders if there are no name conflicts; see bugs #363 and #1735 if (lmoc != NoSymbol && !c.symbol.hasFlag(Flags.INTERFACE)) { - // forwarders were creating many issues, see #1795 for instance; so for now - // they are only enabled if -Xforwarders is supplied to scalac... - if (settings.forwarders.value) { - log("Adding forwarders to existing class " + c.symbol + " found in module " + lmoc) + if (isCandidateForForwarders(lmoc) && !settings.noForwarders.value) { + log("Adding forwarders to existing class '%s' found in module '%s'".format(c.symbol, lmoc)) addForwarders(jclass, lmoc.moduleClass) } - // ...but we special case main so at least ticket #363 can continue to work. - // XXX we would like to, but doing so induces #1795 as surely as adding them all. - // else addForwarders(jclass, lmoc.moduleClass, _.name == nme.main) } } @@ -786,8 +787,10 @@ abstract class GenJVM extends SubComponent { if (settings.debug.value) log("Dumping mirror class for object: " + module); - for (m <- module.info.nonPrivateMembers; if shouldForward(m) ; if cond(m)) + for (m <- module.info.nonPrivateMembers; if shouldForward(m) ; if cond(m)) { + log("Adding static forwarder '%s' to '%s'".format(m, module)) addForwarder(jclass, module, m) + } } /** Dump a mirror class for a top-level module. A mirror class is a class containing diff --git a/test/pending/pos/t1745/J.java b/test/files/pos/t1745/J.java index 8444eabb24..8444eabb24 100644 --- a/test/pending/pos/t1745/J.java +++ b/test/files/pos/t1745/J.java diff --git a/test/pending/pos/t1745/S.scala b/test/files/pos/t1745/S.scala index 70210ba502..70210ba502 100644 --- a/test/pending/pos/t1745/S.scala +++ b/test/files/pos/t1745/S.scala diff --git a/test/pending/run/bug363.check b/test/files/run/bug363.check index 040b97c07a..040b97c07a 100644 --- a/test/pending/run/bug363.check +++ b/test/files/run/bug363.check diff --git a/test/pending/run/bug363.scala b/test/files/run/bug363.scala index 104629016e..104629016e 100644 --- a/test/pending/run/bug363.scala +++ b/test/files/run/bug363.scala |