Repository navigation
fix(swift): recover switch-case uses of modifier-named locals (#5006) - #5641
Komorebi-GZM wants to merge 2 commits into
Conversation
…fy-Labs#5006) tree-sitter-swift 0.7.4 reads a contextual-modifier identifier used as a value after `return` in a switch case body (`return prefix + "a"`) as a declaration modifier, so the switch collapses into ERROR nodes and the file is only partially extracted. Group those misread identifiers with parentheses (valid Swift) before parsing. The rewrite is kept only when it makes the whole file parse cleanly; a file that already parses, or that still has errors afterwards, is left untouched. Bump the AST cache schema to 60 so cached Swift inputs re-extract.
|
Thanks for the pull request, @Komorebi-GZM. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify review 
8 possible issues to check · High impact
Swift extraction now retries parsing when modifier-named identifiers in switch cases cause syntax errors, and reuses the recovered parse tree.
8 possible issues we couldn't confirm
- C++ files with CRLF line endings can reuse a tree whose byte offsets no longer match the normalized source ·
graphify/extractors/engine.py:8513 - A caller-supplied syntax tree is trusted without checking that it was parsed from the bytes being read ·
graphify/extractors/engine.py:8487 - The PR title describes a Swift switch-case fix, but this file only adds an optional tree argument to the generic extractor ·
graphify/extractors/engine.py:8487 - +5 more in Graphify
They don't change the score.
What this review covered
- 1 more candidate was not reported: the cited line wasn't in code the review read.
- We didn't review 1 file that isn't source code, such as docs, config, images, or generated or third-party code.
- A changed file's diff was too long to show in full, so the review may not have seen every changed line in it.
- 4 of 4 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 6751 functions depend on this change
- 1 function became more coupled.
extract_swift()(34 callers). - 659 of 659 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed 62e2aa5 · 1 of 1 earlier findings resolved · 6 earlier findings not re-checked
Coordination notes for this PR (from the same account's other workstream)Posting here so the notes travel with the PR notifications:
Our sibling PR #5622 (TypeScript const-alias call edges) is parked waiting for maintainer review with 4 rounds of red-green fixes and a semantic matrix posted — see its issue thread for the reviewer-tested pattern. |
…cases (Graphify-Labs#5006) Accept the graphify-labs review on Graphify-Labs#5641: a clean Swift file is extracted from the normalizer's tree instead of being parsed twice, and modifier parentheses are inserted only inside a switch case. Collected spans are disjoint identifier ranges, so right-to-left insertion is unchanged. AST cache schema 60 -> 61.
Extractor accuracy (Swift #5641, Apex #5627, Python #5647, TypeScript #5604/#5614/#5612, Bash caller-var #5602), GitHub Actions run-step extraction (#5603), incremental correctness (#5634/#5638/#5636), symlink and semantic-cache fixes (#5617/#5618), export/report hardening and perf (#5643/#5644/#5645/#5646/#5619/#5620/#5621), and CLI/docs/skill/install work (#5629/#5628/#5626/#5624/#5623/#5625/#5642/#5583). AST cache schema 59 to 60; Swift/Apex/Python/Bash/GHA inputs re-extract on first build. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in v0.9.124 (just released to PyPI), cherry-picked with your authorship preserved so it shows under your name in the history. Thanks @Komorebi-GZM for recovering switch-case uses of modifier-named Swift locals — verified green in the full suite and, where applicable, smoke-tested against the published package. 🙏 |
Closes #5006.
What
tree-sitter-swift 0.7.4 (the newest pin under
>=0.7,<0.9) reads a contextual-modifier identifier used as a value afterreturnin aswitchcase body —return prefix + "a",return prefix.count— as a declaration modifier waiting for a declaration. Theswitchcollapses into ERROR nodes and the file is only partially extracted (parse_errors, andswitch kind { ... }is misread as a call tokind).Fail-closed fix (CONTRIBUTING item 5), in
extract_swift:ERRORnode are grouped with parentheses (valid Swift) and the file is re-parsed.Real declaration modifiers (
prefix func,open class,final class,override func) are not rewritten: they are not children ofERROR.The AST cache schema bumps 59 → 60 so cached Swift inputs re-extract.
Tests
tests/test_swift_switch_modifier_idents.py:return ident + "a"andreturn ident.count) have noparse_errorsand no fabricatedkindcall.return prefix,if(notswitch), and realprefix/open/final/overridedeclarations still parse and are not rewritten away.parse_errorsstay).On tree-sitter-swift 0.7.4, the operator/member cases fail without the change and pass with it. Existing Swift suites still pass (65 tests in the focused run).
Base: Graphify-Labs/graphify
v8@5d962d2(0.9.123).