Skip to content

Java grammar: array class literals (String[].class) and array-constructor method references (TimeUnit[]::new) #142

Description

@prozak

Motivation

The largest remaining corpus bucket after PR #132: 13 files (4 main, 9 tests) fail first on an array type used as a non-declarator base — String[].class, Type[].class, Boolean[].class (class literals, JLS 15.8.2) and boolean[]::new, TimeUnit[]::new (array-constructor references, JLS 15.13). Both are explicitly documented as not covered in the NOTEs at PrimaryNoPostfix ("Array class literals (String[].class) are not covered") and PostfixExpression ("NOT covered (rare): array-type refs ('String[]::new')"). They turned out not to be rare in commons-lang's reflection-heavy code.

Sketch

Two anchored alternative groups, one per base kind:

  • Class literals: alongside the existing id CompoundNameTail '.' 'class' alternative, add id CompoundNameTail NonEmptyDims '.' 'class', plus a primitive twin PrimitiveTypeKeyword NonEmptyDims '.' 'class' (for int[].class). The [ rides the existing family-4 shift; after a complete empty pair, . currently dead-ends in expression states (only declarator/type continuations exist), so the . shift should be fresh — verify against the family-4 states in the inventory and update it.
  • Constructor refs: :: is a fresh token no reduce lookahead contains (the zero-conflict argument documented at PostfixExpression), so add dims'd-base forms next to the existing PostfixExpression '::' 'new', anchored the same way as the class literals (id CompoundNameTail NonEmptyDims '::' 'new' and a primitive twin) rather than through PostfixExpression, to survive the greedy name shift (family 3).

These two share the same name [ / primitive [ head analysis, hence one issue; fixing only one leaves most of the bucket failing (several files use both).

Acceptance

Probe covering String[].class, int[].class, boolean[]::new, TimeUnit[]::new in argument and assignment positions, wired into make test-all-java; standard protocol from PR #132 (accept-golden + diff review, full Java battery, family-4 conflict delta documented in the java.pg inventory, corpus rerun, blacklist update with header counts, make test-parse-commons-lang-all green).

Part of the java.pg coverage work (#21); counts are first-failure causes.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    java-grammarjava.pg coverage and conflict work

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions