SC2329 false positive when calling function via variable
Opened this issue · 3 comments
MichaIng commented
For bugs with existing features
- Rule Id (if any, e.g. SC1000): SC2329
- My shellcheck version (
shellcheck --versionor "online"): 0.11.0 - The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
- I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit
Here's a snippet or screenshot that shows the problem:
#!/bin/bash
func1(){ echo 'func1 called'; }
i=1
"func${i}"
exit 0Here's what shellcheck currently says:
In test line 2:
func1(){ echo 'func1 called'; }
^-----------------------------^ SC2329 (info): This function is never invoked. Check usage (or ignored if invoked indirectly).Here's what I wanted or expected to see:
Nothing, since the function is called. It might be expected behavior, similar to how function calls from traps are not recognized (yet), but at least the wiki does not mention it. There are other checks where shellcheck takes into account variables, so probably it is possible here as well for unconditionally assigned variables.
litaocdl commented
+1,
trap function is exposed as not been used.
es20490446e commented
I'm experiencing this bug too since today.
Not through trap though.
The problematic code is:
package_rust-aarch64-gnu () {
SetAarch64GnuVars
PackageModule "aarch64-gnu"
}
SetAarch64GnuVars () {
pkgdesc="Allows using Rust on AArch64 GNU"
depends=(
"aarch64-linux-gnu-gcc"
"aarch64-linux-gnu-glibc"
"rust"
)
}
SetAarch64GnuVars is detected as never being executed.
This is a PKGBUILD (link). Hence package_rust-aarch64-gnu is never explicitly executed within the file, but by the tool makepkg.
Still the wrong function name is detected.
es20490446e commented