Skip to content

fix: allow scoped type identifiers in record patterns - #232

Open
mihailkirov wants to merge 1 commit into
tree-sitter:masterfrom
mihailkirov:record-pattern-scoped-type
Open

mihailkirov wants to merge 1 commit into
tree-sitter:masterfrom
mihailkirov:record-pattern-scoped-type

Conversation

@mihailkirov

Copy link
Copy Markdown

A record pattern headed by a qualified type name produces an ERROR node:

// switch
case Result.Authorized(Contracts.Id id) -> id.toString();
// instanceof
if (obj instanceof Shapes.Rectangle(Shapes.ColoredPoint ul)) { }

record_pattern's head choice is identifier / _reserved_identifier / generic_type — no scoped_type_identifier — while type_pattern already accepts any _unannotated_type (which includes scoped_type_identifier). Java 21 codebases use the qualified form whenever the record is a nested type named through its enclosing type, and every upstream tag back to v0.20.2 errors on it (reported downstream as semgrep/semgrep#11954).

This PR adds scoped_type_identifier to the choice. Regenerated with tree-sitter CLI 0.26.13 at the committed ABI (14): no new conflicts (only the pre-existing _simple_type supertype warning), STATE_COUNT 1378 → 1388. Adds a corpus test covering both the instanceof and the switch-label form; tree-sitter test passes 109/109.

A record pattern headed by a qualified type name — case A.B.Authorized(Id
id) -> in a switch, or o instanceof R.Found(Doc d) — produces an ERROR
node, because record_pattern's head choice is identifier /
_reserved_identifier / generic_type with no scoped_type_identifier. Java
21 codebases use the qualified form whenever the record is a nested type
named through its enclosing type. Add scoped_type_identifier to the
choice, mirroring what _unannotated_type already allows in a type_pattern.

Regenerated with tree-sitter CLI 0.26.13 at the committed ABI (14); adds a
corpus test covering both the instanceof and the switch-label form.
Reported downstream as semgrep/semgrep#11954.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant