Skip to content

fix: splat binds to the whole operand; only a name on the left of a type alias - #365

Open
mimo1999 wants to merge 2 commits into
tree-sitter:masterfrom
mimo1999:fix/splat-and-type-alias
Open

mimo1999 wants to merge 2 commits into
tree-sitter:masterfrom
mimo1999:fix/splat-and-type-alias

Conversation

@mimo1999

@mimo1999 mimo1999 commented Dec 3, 2026

Copy link
Copy Markdown

Fixes #314
Fixes #321

Two separate commits; happy to split them into two PRs if you prefer.

1. Splat binds to the whole operand (#314)

[*a.b(c).d] parsed as an attribute whose object was a list_splat, because a splat pattern was itself a primary_expression. A starred expression is now an expression over a whole primary_expression, so [*a.b], {*a.b} and x = *f(), y get the same list_splat shape that f(*a.b) already had.

The existing Lists corpus test expected the old (wrong) tree for [*a.b], [*a()] etc., so its expected output is updated. This is a correction of the test, not a relaxation. A Sets case was added.

list_splat moves from a primary_expression subtype to an expression subtype, which changes node-types.json.

2. Only a name on the left of a type alias (#321)

type(x).y = 1 and type(x)[0] = 1 parsed as a type_alias_statement with no ERROR node. PEP 695 only allows a name, optionally with type parameters, so the left side is now an identifier or generic_type. That removes the need for the [type_alias_statement, primary_expression] conflict. type X = int, type X[T] = ..., type = 1 and print(type) parse as before.

Testing

  • tree-sitter test: 122 passed, 0 failed.
  • Parsed CPython's standard library (1,731 files) before and after. No file gained an error; the 18 trees that changed are all the intended splat fix.
  • parser.c regenerated with tree-sitter CLI 0.25.9, the version already used in the repo; the large diff is state renumbering.
  • I couldn't run the Node/Rust/Python binding tests locally (no MSVC on this machine), so I'm relying on CI for those.

🤖 Generated with Claude Code

`*` bound tighter than `.`, `(` and `[`: `[*a.b(c).d]` parsed as an
attribute whose object was `list_splat`, because a splat pattern was
itself a primary expression. A starred expression is now an expression
over a whole primary expression, so `[*a.b]`, `{*a.b}` and
`x = *f(), y` get the same `list_splat` shape as `f(*a.b)`.

The `Lists` corpus test expected the old shape and is updated.

Fixes tree-sitter#314
`type(x).y = 1` parsed as a `type_alias_statement` with no error,
because the left side of an alias accepted any type. PEP 695 only
allows a name, optionally with type parameters, so the left side is now
an identifier or a generic type. That makes the conflict with
`primary_expression` unnecessary, and `type(x).y = 1` and
`type(x)[0] = 1` parse as assignments.

Fixes tree-sitter#321

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.

bug: Assignment incorrectly parsed as type_alias_statement bug: list_splat wrongly set in call function

1 participant