Skip to content

lint: W001 (unused variable) never fires inside a match arm #780

Description

@Nitjsefnie

Describe the bug

W001 (unused variable) is never reported for an assignment that exists only inside a match arm. collect_assigns recurses into AST_BLOCK and AST_UNOBSERVED (src/lint.c:344-348) but lists AST_MATCH in its break-only group (src/lint.c:385), so the name is never recorded and the emission loop at src/lint.c:3061-3077 never sees it.

Unlike the sibling gaps, this one is match-onlyunobserved: bodies are walked and do report correctly.

Surfaced while doing #779, which made these switches enumerable; it neither caused nor fixed this. Line numbers resolved against main @ 23edbc25.

To reproduce

Control — reported correctly:

w001_top is 5

Also reported correctly (unobserved: is walked):

unobserved:
    w001_inunobs is 5

Silent — the bug:

match 1:
    case 1:
        w001_inmatch is 5
    case _:
        w001_inmatch2 is 6

Expected behavior

warning[W001]: unused variable 'w001_inmatch' (and 'w001_inmatch2'), as the top-level and unobserved: cases already produce.

Actual behavior

$ eigenscript --lint w001_control.eigs
w001_control.eigs:1: warning[W001]: unused variable 'w001_top'
$ eigenscript --lint w001_unobs.eigs
w001_unobs.eigs:2: warning[W001]: unused variable 'w001_inunobs'
$ eigenscript --lint w001_match.eigs
w001_match.eigs: no issues found

The program runs (exit 0), so this is live code the linter is silent on, not a parse artifact.

Environment

  • OS: Debian 13 (x86_64)
  • GCC version: 14
  • EigenScript version: 0.34.0 (main @ 23edbc25)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions