Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse concrete private interface methods in Java #12956

Closed
magnolia-k opened this issue Jun 27, 2021 · 0 comments · Fixed by #14643
Closed

Parse concrete private interface methods in Java #12956

magnolia-k opened this issue Jun 27, 2021 · 0 comments · Fixed by #14643

Comments

@magnolia-k
Copy link
Contributor

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants