lint: recurse W003 into unobserved blocks and match arms - #792
Merged
InauguralPhysicist merged 1 commit intoAug 2, 2026
Merged
Conversation
…match arms (InauguralSystems#782) check_func_unreachable recursed only through IF/LOOP/FOR/FUNC/TRY/PROGRAM, breaking on AST_UNOBSERVED and AST_MATCH, so a function defined inside an unobserved block or a match arm never had its body scanned and W003 never fired there while the same dead code at top level warned. Recurse into both, matching the shape check_builtin_shadow (InauguralSystems#787) already uses for these node types. Diagnostics themselves are unchanged. Closes InauguralSystems#782 Co-Authored-By: Kimi K3 <noreply@kimi.com>
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #782.
check_func_unreachablerecursed only throughAST_IF/LOOP/FOR/FUNC/TRY/PROGRAMand kept bothAST_MATCHandAST_UNOBSERVEDin its break-only group, so a function defined inside anunobserved:block or amatcharm was never reached, its body was never handed tocheck_unreachable, and the W003 emission never fired.Both arms were missing here, so this adds both — unlike #790, where the walker already recursed
AST_UNOBSERVEDand onlyAST_MATCHwas needed. The recursion idiom ischeck_builtin_shadow's from #787 verbatim:AST_MATCHdescendscase_count×body_counts[i]overbodies[i][j],AST_UNOBSERVEDdescendsblock.countoverblock.stmts[i].Changes
src/lint.c— two recursion arms added tocheck_func_unreachableimmediately after the existingAST_PROGRAMarm; both labels removed from the break-only group. No new traversal helper, no change to the emission site, no other walker touched.tests/test_lint.sh— two tests, placed mid-file next to the existing W003 coverage rather than appended at the tail, since lint: W002 (unused parameter) never fires for a function defined inside unobserved: or a match arm #781 and lint: W010 (duplicate dict key) never fires inside unobserved: or a match arm #783 are adding tests to this same file.Testing
bash tests/test_lint.shrun directly for its exit code:122 passed, 0 failed, 122 total, exit 0.tests/run_all_tests.sh:RESULTS: 3314/3314 passed, 0 failed.src/lint.creverted to upstream and the new tests kept, both fail (120 passed, 2 failed).AST_MATCHalone silences the match reproducer and fails exactly the match test; neutralisingAST_UNOBSERVEDalone silences theunobserved:reproducer and fails exactly that test.main(1750b48), builds clean,tests/test_lint.shexit 0.lib/+examples/+tests/(397.eigsfiles, each linted individually): zero W003 hits.fuzz/corpus/was deliberately left out of that scope.One note that will show in the logs but is not from this PR:
src/lint.calready emits three compiler warnings onmain(:825,:844,:911), all outside this diff.Checklist
make testpasses locally — full suite viatests/run_all_tests.sh:3314/3314 passed, 0 failed; lint tests run directly for their exit code,122 passed, 0 failed, exit 0docs/BUILTINS.md— n/a, no new builtinsdocs/STDLIB.md— n/a, no new library functionssrc/lint.candtests/test_lint.sh. Happy to add an entry if you'd rather these carried one.Generated by Claude Opus 5 (brief, review), Kimi K3 (implementation, verification)