Skip to content

Commit 11f8cda

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 43f6010 commit 11f8cda

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
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
@@ -167,7 +167,7 @@ abstract class BCodeSkelBuilder extends BCodeHelpers {
167167

168168
} else {
169169

170-
val skipStaticForwarders = (claszSymbol.isInterface || settings.noForwarders)
170+
val skipStaticForwarders = settings.noForwarders
171171
if (!skipStaticForwarders) {
172172
val lmoc = claszSymbol.companionModule
173173
// 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)