diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/javac/JavaParsers.scala | 5 | ||||
-rw-r--r-- | test/files/run/t8852a.scala | 34 |
2 files changed, 37 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala index 37b00aa9a3..9433ddcf31 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala @@ -488,7 +488,8 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { val vparams = formalParams() if (!isVoid) rtpt = optArrayBrackets(rtpt) optThrows() - val bodyOk = !inInterface || (mods hasFlag Flags.DEFAULTMETHOD) + val isStatic = mods hasFlag Flags.STATIC + val bodyOk = !inInterface || ((mods hasFlag Flags.DEFAULTMETHOD) || isStatic) val body = if (bodyOk && in.token == LBRACE) { methodBody() @@ -507,7 +508,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { EmptyTree } } - if (inInterface) mods1 |= Flags.DEFERRED + if (inInterface && !isStatic) mods1 |= Flags.DEFERRED List { atPos(pos) { DefDef(mods1, name.toTermName, tparams, List(vparams), rtpt, body) diff --git a/test/files/run/t8852a.scala b/test/files/run/t8852a.scala new file mode 100644 index 0000000000..cbff8ab75b --- /dev/null +++ b/test/files/run/t8852a.scala @@ -0,0 +1,34 @@ +import scala.tools.partest._ + +// Test that static methods in Java interfaces (new in Java 8) +// are callable from jointly compiler Scala code. +object Test extends CompilerTest { + import global._ + + override lazy val units: List[CompilationUnit] = { + // This test itself does not depend on JDK8. + javaCompilationUnits(global)(staticMethodInInterface) ++ + compilationUnits(global)(scalaClient) + } + + private def staticMethodInInterface = """ +public interface Interface { + public static int staticMethod() { + return 42; + } +} + + """ + + private def scalaClient = """ +object Test { + val x: Int = Interface.staticMethod() +} + +class C extends Interface // expect no errors about unimplemented members. + + """ + + // We're only checking we can compile it. + def check(source: String, unit: global.CompilationUnit): Unit = () +} |