shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

SC2329 false positive when calling function via variable

Open MichaIng opened this issue 5 months ago • 5 comments

For bugs with existing features

  • Rule Id (if any, e.g. SC1000): SC2329
  • My shellcheck version (shellcheck --version or "online"): 0.11.0
  • [x] The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
  • [x] 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 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.

MichaIng avatar Aug 04 '25 23:08 MichaIng

+1,

trap function is exposed as not been used.

litaocdl avatar Aug 11 '25 03:08 litaocdl

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 avatar Aug 11 '25 10:08 es20490446e

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

es20490446e avatar Aug 11 '25 10:08 es20490446e

This affects traps as well, eg

trap on_exit INT TERM EXIT
on_exit() { rm -r "${tempfiles[@]}"; }

hseg avatar Nov 11 '25 01:11 hseg

Right, as mentioned at the end of my post. See also #2542 in these regards.

MichaIng avatar Nov 11 '25 14:11 MichaIng