Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect "Unused local variable" inspection #139

Open
szhorvat opened this issue Oct 23, 2019 · 0 comments
Open

Incorrect "Unused local variable" inspection #139

szhorvat opened this issue Oct 23, 2019 · 0 comments
Assignees
Labels
bug

Comments

@szhorvat
Copy link
Contributor

@szhorvat szhorvat commented Oct 23, 2019

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.

@halirutan halirutan added the bug label Oct 23, 2019
@halirutan halirutan added this to High priority in Version 2020.1 Goals Dec 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Version 2020.1 Goals
  
High priority
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.