koalaman/shellcheck

SC2329 false positive when calling function via variable

Opened this issue · 3 comments

For bugs with existing features

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

#!/bin/bash
func1(){ echo 'func1 called'; }
i=1
"func${i}"
exit 0

Here'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.

+1,

trap function is exposed as not been used.

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.

This regression was likely introduced in this commit, by @koalaman.