You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Swift: a local with same name as a modifier (prefix, open, final...) used in a switch case body gives a syntax-parse error from tree-sitter-swift #5006
I have checked the Troubleshooting section in the README
What happened?
Summary: tree-sitter-swift 0.7.4 cannot parse a local value whose name is a Swift contextual modifier when it is used as return name <operator> or return name.member inside a switch case. The grammar reads the identifier as a declaration modifier waiting for a declaration, and the surrounding code collapses into ERROR nodes. Graphify warns about a syntax-parse error at line: X and extracts the file only partially.
Related but distinct: #3540 (another tree-sitter-swift parse failure, if let x = await ...).
The trigger is a modifier-named identifier at the start of an expression statement inside a case body, followed by an operator or member access.
Limits and unfixed exceptions (the fix doesn't cover these, so behavior is unchanged: partial extraction plus the warning):
A function parameter named like a modifier. Renaming it would change the argument label and every call site.
A closure parameter, as in xs.map { prefix in ... }.
Tuple destructuring, as in let (prefix, b) = t.
A file with any other syntax error, because the rewrite is accepted only if the whole file then parses cleanly.
Names I haven't tested. The list is only what I verified.
Covered:if let prefix = x, and a type-scope property with the same name.
Code change: added six names that also fail to extract.py, the test parametrization, and the changelog: distributed, nonmutating, public, private, internal and fileprivate.
Validation: The Swift tests pass, 36 of 36 in the two files I re-ran after the change. I did not re-run the full suite because it had 8 failures before this change, and they also fail without this fix.
static, class and inout also error, but they are reserved keywords, so let class = 1 isn't valid Swift.
Steps to reproduce
Minimal repro
let prefix = "x"
switch kind {
case 0:
return prefix + "a" // error
Case body
Result
return prefix + "a"
error
return prefix.count > 0 ? "a" : "b"
error
return prefix
ok
print(prefix)
ok
let y = prefix
ok
x = prefix + "a"
ok
return "a" + prefix
ok
return pfx + "a" (local renamed)
ok
return prefix + "a" inside if k == 0 { ... } instead of a switch
ok
return prefix + "a" after the switch, outside any case
ok
Error output or graph output
codefile.swift had a syntax-parse error at line X, so its extraction may be partial (Y symbols found).
Activity
github-actions commentedon Nov 4, 2026
Thanks for opening this issue, @jwpnet. A maintainer will take a look soon.
If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.
To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.
jwpnet commentedon Nov 4, 2026
I have a fix I will submit also
Komorebi-GZM commentedon Nov 30, 2026
We've opened a pull request with a fail-closed workaround for this tree-sitter-swift parse failure: #5641.
@jwpnet — you mentioned you also had a fix to submit. Sorry if this overlaps; happy to defer or adjust if you'd still like to land yours.
fix(swift): reuse clean parse tree and wrap modifiers only in switch …
fix(swift): recover switch-case uses of modifier-named locals (Graphi…