Skip to content

Cannot parse Java file with type annotations on array or path selection #19642

Closed
@bishabosha

Description

@bishabosha

Compiler version

3.4.0-RC4

Minimized code

// TpeAnnot.java

package lib;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})
public @interface TpeAnnot {}
// TpeAnnotated.java

package lib;

public class TpeAnnotated {

  private static <T> T unimplemented() {
    return null;
  }

  public class C {
    public class D {}
  }

  public static int @TpeAnnot [] g() { return unimplemented(); } // error

  public static int @TpeAnnot [][] h() { return unimplemented(); } // error

  public static int[] @TpeAnnot [] i() { return unimplemented(); } // error

  public static C.@TpeAnnot D foo2() { return unimplemented(); } // error

}

Output

these errors do not appear all at the same time, but by commenting out the appropriate lines of one error to reveal another one.

-- Error: TpeAnnotated.java:11:20 ----------------------------------------------
11 |  public static int @TpeAnnot [] g() { return unimplemented(); } // error
   |                    ^^^
   |                    identifier expected but @ found.
-- Error: TpeAnnotated.java:13:20 ----------------------------------------------
13 |  public static int @TpeAnnot [][] h() { return unimplemented(); } // error
   |                    ^^^
   |                    identifier expected but @ found.
-- Error: TpeAnnotated.java:15:22 ----------------------------------------------
15 |  public static int[] @TpeAnnot [] i() { return unimplemented(); } // error
   |                      ^^^
   |                      identifier expected but @ found.
-- Error: TpeAnnotated.java:23:18 ----------------------------------------------
23 |  public static C.@TpeAnnot D foo2() { return unimplemented(); } // error
   |                  ^
   |                  identifier expected but @ found.
-- Error: TpeAnnotated.java:26:0 -----------------------------------------------
26 |}
   |^
   |identifier expected but '}' found.
2 errors found

Expectation

This is valid java accepted by Javac, see JLS 4.11. Note that this fails to parse in Scala 2.13 also

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions