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

[java] Java8 parsing corner case with annotated array types #997

oowekyala opened this Issue Mar 23, 2018 · 0 comments


None yet
3 participants
Copy link

oowekyala commented Mar 23, 2018


With Java 8 type annotations, the dimensions of an array may each have different annotations, which our parser actually doesn't support... There are several instances of this problem:

Type node

      // Doesn't parse
      int @Foo[]@Bar[] i;


Our grammar:

Array creation expression

   // Doesn't parse
    new int @Foo[2] @Bar[];


Our grammar:


class Foo {
  int i @Bar[]; // field declaration

  void bar(int i@Bar[]) { // formal parameter 
    int i @Bar[]; // local variable declaration


Our grammar:

Method declarations

The JLS allows array dimensions (including annotations) to be added after the formal parameter list, eg:

  int method()@Foo[]@Bar[] {
        return new int[2][];

By the way, even without annotations, the parser currently discards the additionnal array dimensions, though it should be used in type resolution:

This is related to the broader #910 changeset


  • Add a node for the array dimensions, which resembles the JLS for the Dims production. This wouldn't be API breaking, provided we make the dimensions of eg ReferenceType delegate to that Dims node.
  • Dimensionable should probably be deprecated entirely, and we could use a new interface to replace it that exposes the annotations and the dimensions for type resolution, based on the Dims node
  • To make the method return type resolution work correctly, we could make ReturnType a Dimensionable (and a TypeNode), and add the dimensions of the Dims node found in the method declarator to the dimensions found in the type node.

I imagine that could be 3 PRs

@oowekyala oowekyala added the a:bug label Mar 23, 2018

@oowekyala oowekyala self-assigned this Mar 23, 2018

@oowekyala oowekyala added this to the 6.3.0 milestone Mar 23, 2018

@adangel adangel modified the milestones: 6.3.0, 6.4.0 Apr 28, 2018

@adangel adangel modified the milestones: 6.4.0, 6.5.0 May 19, 2018

@oowekyala oowekyala added the in:ast label May 27, 2018

@jsotuyod jsotuyod modified the milestones: 6.5.0, 6.6.0 Jun 26, 2018

@adangel adangel modified the milestones: 6.6.0, 6.7.0 Jul 29, 2018

@adangel adangel modified the milestones: 6.7.0, 6.8.0 Sep 1, 2018

@oowekyala oowekyala removed this from the 6.8.0 milestone Sep 29, 2018

@oowekyala oowekyala added this to the 7.0.0 milestone Nov 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment