Skip to content

Commit 0a7f937

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. ``` % 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 93f209d commit 0a7f937

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ abstract class BCodeSkelBuilder extends BCodeHelpers {
164164

165165
} else {
166166

167-
val skipStaticForwarders = (claszSymbol.isInterface || settings.noForwarders)
168-
if (!skipStaticForwarders) {
167+
if (!settings.noForwarders) {
169168
val lmoc = claszSymbol.companionModule
170169
// add static forwarders if there are no name conflicts; see bugs #363 and #1735
171170
if (lmoc != NoSymbol) {
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)