Skip to content
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

SC2034 doesn't consider local function definitions to define new scopes #2965

Open
2 tasks done
hseg opened this issue Apr 10, 2024 · 0 comments
Open
2 tasks done

SC2034 doesn't consider local function definitions to define new scopes #2965

hseg opened this issue Apr 10, 2024 · 0 comments

Comments

@hseg
Copy link

hseg commented Apr 10, 2024

For bugs

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

#!/bin/bash

ppArrInd() {
    local -n args="$1"
    printf '<%s>\n' "${args[@]}"
}

case "$1" in
    0) main() {
        local param=(foo bar)
        ppArrInd param
    };;
    1) main() {
        local param=(baz quz)
        ppArrInd param
    };;
    *) main() {
        local param=(fizz buzz)
        ppArrInd param
    };;
esac
main

Here's what shellcheck currently says:

SC2034 is triggered unless specifically it is disabled on the last definition of param

Here's what I wanted or expected to see:

Given that realizing that an array is passed by name is out-of-scope for SC2034, at least it should warn at each of the definition lines for param (either since it understands that these are distinct variables, or since "is later redefined" should not count as a usage -- I'd similarly expect x=1; x=2; x=3 to warn that each of these definitions of x are unused)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant