shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

SC2034 doesn't consider namerefs

Open zx2c4 opened this issue 8 years ago • 5 comments

Shellcheck doesn't account for namerefs properly.

For bugs

  • Version: 4.5 and online
  • I tried on 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
read_bool() {
        local -n out="$1"
        case "$2" in
        true) out=1 ;;
        false) out=0 ;;
        *) die "\`$2' is neither true nor false"
        esac
}

Here's what shellcheck currently says:

        false) out=0 ;;
               ^-- SC2034: out appears unused. Verify it or export it.

Here's what I wanted or expected to see:

Nothing.

zx2c4 avatar Jan 05 '17 01:01 zx2c4

Hey @koalaman - might I poke you about this?

Namerefs are an important feature of bash.

zx2c4 avatar Mar 23 '17 14:03 zx2c4

No updates, but you're right. Namerefs should be considered auto-used just like exported variables.

koalaman avatar Apr 02 '17 01:04 koalaman

Duplicates of this issue: #1544 #1543

pabs3 avatar Jun 28 '20 05:06 pabs3

More apparent duplicates: #2919

hseg avatar Apr 10 '24 18:04 hseg

7.5 year old issue now. Constant annoyance in our workflow. SC2034 is very helpful when it works correctly in identifying stray vars that need to be cleaned up, but cannot recognize any kind of nameref usage; not with a declare/local -n, not when adding entries to that ref, and not when using the ref in another function:

myfunc() {
    local -n out="${1}" str="${2}"
    str="${out[*]}"
}
array=(1 2 3)
declare -n ref="array"
ref+=(4)
myfunc ref string
echo "${string}"

IMG_4291

oklopfer avatar Jul 30 '24 17:07 oklopfer