-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
SC2178 not respecting local declaration: Variable was used as an array but is now assigned a string #1225
Comments
I think this is because the dataflow analysis shellcheck has is not complete. There is an open TODO in the code to make it better. |
I have another example if scope bleeding across functions (cut 'n pasted from https://www.shellcheck.net/ instead of starting a new issue):
|
SC2178 not respecting local declaration: "Variable was used as an array but is now assigned a string #1225" See koalaman/shellcheck#1225
This is another simple example I came across: #!/bin/bash
f1() {
local cmd
cmd=(echo array)
}
f2() {
local cmd="echo string"
echo "$cmd"
} Errors with shellcheck version 0.8.0:
|
Despite being declared as
local
within separate functions,shellcheck
complains about a variable being used as both an array and a scalar.Even if they weren't locally scoped, In this particular case, declaring with
-n
should obviate this error.For bugs
Here's a snippet or screenshot that shows the problem:
Here's what shellcheck currently says:
Here's what I wanted or expected to see:
No error
Workaround
The error disappears if I reorder the references, but I don't think there should be any semantic difference.
The text was updated successfully, but these errors were encountered: