From 41c9a17e4f211fc24a931949a0819a0474cc004a Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 19 May 2016 16:23:23 +1000 Subject: Generate static forwarders for object members in companion interface (#5131) 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. Fixes https://github.com/scala/scala-dev/issues/59 --- src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala | 3 +-- test/files/run/trait-static-forwarder.check | 1 + test/files/run/trait-static-forwarder/Test.java | 5 +++++ test/files/run/trait-static-forwarder/forwarders.scala | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 test/files/run/trait-static-forwarder.check create mode 100644 test/files/run/trait-static-forwarder/Test.java create mode 100644 test/files/run/trait-static-forwarder/forwarders.scala diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala index f190c1f2de..bddc41e5c6 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala @@ -164,8 +164,7 @@ abstract class BCodeSkelBuilder extends BCodeHelpers { } else { - val skipStaticForwarders = (claszSymbol.isInterface || settings.noForwarders) - if (!skipStaticForwarders) { + if (!settings.noForwarders) { val lmoc = claszSymbol.companionModule // add static forwarders if there are no name conflicts; see bugs #363 and #1735 if (lmoc != NoSymbol) { diff --git a/test/files/run/trait-static-forwarder.check b/test/files/run/trait-static-forwarder.check new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/test/files/run/trait-static-forwarder.check @@ -0,0 +1 @@ +42 diff --git a/test/files/run/trait-static-forwarder/Test.java b/test/files/run/trait-static-forwarder/Test.java new file mode 100644 index 0000000000..89012c0162 --- /dev/null +++ b/test/files/run/trait-static-forwarder/Test.java @@ -0,0 +1,5 @@ +public final class Test { + public static void main(String... args) { + System.out.println(T.foo()); + } +} diff --git a/test/files/run/trait-static-forwarder/forwarders.scala b/test/files/run/trait-static-forwarder/forwarders.scala new file mode 100644 index 0000000000..d6ee9a081d --- /dev/null +++ b/test/files/run/trait-static-forwarder/forwarders.scala @@ -0,0 +1,5 @@ +trait T + +object T { + def foo = 42 +} -- cgit v1.2.3