Skip to content

Commit b73c291

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 a05e3ce commit b73c291

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ abstract class BCodeSkelBuilder extends BCodeHelpers {
169169

170170
} else {
171171

172-
val skipStaticForwarders = (claszSymbol.isInterface || settings.noForwarders)
172+
val skipStaticForwarders = settings.noForwarders
173173
if (!skipStaticForwarders) {
174174
val lmoc = claszSymbol.companionModule
175175
// add static forwarders if there are no name conflicts; see bugs #363 and #1735
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
42
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+
}
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)