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

SC2154 var is referenced but not assigned not triggered if used within an array #2970

Closed
4 tasks
robstoll opened this issue Apr 23, 2024 · 1 comment
Closed
4 tasks

Comments

@robstoll
Copy link

robstoll commented Apr 23, 2024

For bugs

For new checks and feature suggestions

Here's a snippet or screenshot that shows the problem:

#!/usr/bin/env bash
a=("$non-existing")
echo "${a[@]}"

Here's what shellcheck currently says:

$ shellcheck myscript
No issues detected!

Here's what I wanted or expected to see:

$ shellcheck myscript
 
[Line 4:](javascript:setPosition(4, 7))
a=("$non-existing")
      ^-- [SC2154](https://www.shellcheck.net/wiki/SC2154) (warning): nonExisting is referenced but not assigned.

I have not contributed code to shellcheck by now but would be willing to write my first PR if I get some pointers :)

@koalaman
Copy link
Owner

koalaman commented May 4, 2024

This was a kludge from back before ShellCheck supported associative arrays. At the time, declare -A x=([y]=z) would treat y as a reference just like , causing a lot of false positives, so the check simply ignored references in arrays.

Parsing of associative arrays has since been fixed, so it was just a matter of removing this kludge. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants