Skip to content

Parse concrete private interface methods in Java #12956

Closed
@magnolia-k

Description

@magnolia-k

Compiler version

Scala compiler version 3.0.0

Minimized code

Interface.java

package example;

public interface Interface {
  private void m() {}
}

Output

$ scalac Interface.java
-- Error: Interface.java:4:19 --------------------------------------------------
4 |  private void m() {}
  |                   ^
  |                   ';' expected but '{' found.
-- [E060] Syntax Error: Interface.java:4:15 ------------------------------------
4 |  private void m() {}
  |               ^
  |               abstract method m may not have `private` modifier
2 errors found

Expectation

Unable to parse private methods of interfaces introduced in Java 9.

Must be able to parse normally.

See the Scala2 issue.

scala/bug#12393

It should be modified as follows.

--- a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala
+++ b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala
@@ -608,7 +608,7 @@ object JavaParsers {
           val vparams = formalParams()
           if (!isVoid) rtpt = optArrayBrackets(rtpt)
           optThrows()
-          val bodyOk = !inInterface || mods.isOneOf(Flags.DefaultMethod | Flags.JavaStatic)
+          val bodyOk = !inInterface || mods.isOneOf(Flags.DefaultMethod | Flags.JavaStatic | Flags.PrivateMethod)
           val body =
             if (bodyOk && in.token == LBRACE)
               methodBody()

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions