Skip to content

Commit 9f6d3b3

Browse files
committed
Generate static forwarders for object members in companion interface
We used to disable generation of static forwarders when a object had a trait as a companion, as one could not add methods with bodies to an interface in JVM 6. The JVM lifted this restriction to support default methods in interfaces, so we can lift the restriction on static forwarders, too. I've only commited the test using the default backend (GenBCode), but I've also made the change and manaully verified the test works under the soon-to-be-removed GenASM. ``` % qscalac -Ybackend:GenASM test/files/run/trait-static-forwarder/forwarders.scala && javac -d . -classpath . test/files/run/trait-static-forwarder/Test.java && qscala Test ./T.class: warning: Cannot find annotation method 'bytes()' in type 'ScalaSignature': class file for scala.reflect.ScalaSignature not found 1 warning 42 ``` Fixes scala/scala-dev#59
1 parent c99e53e commit 9f6d3b3

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ abstract class BCodeSkelBuilder extends BCodeHelpers {
180180

181181
} else {
182182

183-
val skipStaticForwarders = (claszSymbol.isInterface || settings.noForwarders)
183+
val skipStaticForwarders = settings.noForwarders
184184
if (!skipStaticForwarders) {
185185
val lmoc = claszSymbol.companionModule
186186
// add static forwarders if there are no name conflicts; see bugs #363 and #1735

src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { self =>
13041304
for (constructor <- c.lookupStaticCtor) {
13051305
addStaticInit(Some(constructor))
13061306
}
1307-
val skipStaticForwarders = (c.symbol.isInterface || settings.noForwarders)
1307+
val skipStaticForwarders = settings.noForwarders
13081308
if (!skipStaticForwarders) {
13091309
val lmoc = c.symbol.companionModule
13101310
// add static forwarders if there are no name conflicts; see bugs #363 and #1735
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
42
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public final class Test {
2+
public static void main(String... args) {
3+
System.out.println(T.foo());
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trait T
2+
3+
object T {
4+
def foo = 42
5+
}

0 commit comments

Comments
 (0)