Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/lint.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ static void collect_assigns(ASTNode *node, LintContext *ctx) {
for (int i = 0; i < node->data.program.count; i++)
collect_assigns(node->data.program.stmts[i], ctx);
break;
case AST_MATCH:
for (int i = 0; i < node->data.match.case_count; i++)
for (int j = 0; j < node->data.match.body_counts[i]; j++)
collect_assigns(node->data.match.bodies[i][j], ctx);
break;
case AST_TRY:
if (node->data.trycatch.err_name)
add_assign(ctx, node->data.trycatch.err_name, node->line);
Expand Down Expand Up @@ -383,7 +388,6 @@ static void collect_assigns(ASTNode *node, LintContext *ctx) {
case AST_BREAK:
case AST_CONTINUE:
case AST_DOT_ASSIGN:
case AST_MATCH:
case AST_LAMBDA:
case AST_INDEX_ASSIGN:
case AST_LIST_PATTERN_ASSIGN:
Expand Down
28 changes: 28 additions & 0 deletions tests/test_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,34 @@ OUTPUT=$($EIGS --lint "$TMPFILE" 2>&1 || true)
check_contains "#785 W013 fires inside a match arm" "$OUTPUT" "W013.*'chr'"
rm -f "$TMPFILE"

# --- #780: W001 (unused variable) recurses into match arms ---
# collect_assigns used to break on AST_MATCH, so a variable assigned only
# inside a match arm was never recorded and never warned on.
TMPFILE=$(mktemp /tmp/lint_test_XXXXXX.eigs)
cat > "$TMPFILE" << 'EIGS'
match 1:
case 1:
w001_inmatch is 5
print of "done"
EIGS
OUTPUT=$($EIGS --lint "$TMPFILE" 2>&1 || true)
check_contains "#780 W001 fires inside a match arm" "$OUTPUT" "W001.*'w001_inmatch'"
rm -f "$TMPFILE"

TMPFILE=$(mktemp /tmp/lint_test_XXXXXX.eigs)
cat > "$TMPFILE" << 'EIGS'
match 2:
case 1:
print of "one"
case _:
w001_inmatch2 is 6
print of "done"
EIGS
OUTPUT=$($EIGS --lint "$TMPFILE" 2>&1 || true)
check_contains "#780 W001 fires in the fallback match arm" "$OUTPUT" "W001.*'w001_inmatch2'"
rm -f "$TMPFILE"
rm -f "$TMPFILE"

echo ""
echo "Results: $PASS passed, $FAIL failed, $TOTAL total"
exit $FAIL
Loading