Skip to content

Incorrect "Unused local variable" inspection #139

Open
@szhorvat

Description

The "Unused local variable" inspection sometimes triggers incorrectly for a Module variable that is used as a value (i.e. right-hand-side of =) in the variable list of a second enclosed Module.

Code to reproduce it (probably not quite minimal, but almost):

fun[opt : OptionsPattern[]] :=
    Module[{options = Association@Flatten[{opt}]},
      Module[{foo = options["boo"]},
        foo
      ]
    ]

Screenshot:

image


Update with shorter examples.

The following trigger the inspection incorrectly:

Module[{b},
  Module[{a = b},
    a; b
  ]
]
Block[{b},
  Block[{a = b},
    a
  ]
]

The following do not trigger the inspection:

Function[b,
  Module[{a = b},
    a
  ]
]
Block[{b},
  Module[{a = b},
    a
  ]
]

The inner and the outer localizing construct must be the same for the inspection to trigger.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions