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

SC2317 should only trigger once per unreachable code path #2614

Open
2 tasks done
dimo414 opened this issue Oct 24, 2022 · 1 comment
Open
2 tasks done

SC2317 should only trigger once per unreachable code path #2614

dimo414 opened this issue Oct 24, 2022 · 1 comment

Comments

@dimo414
Copy link
Contributor

dimo414 commented Oct 24, 2022

For bugs

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

#!/bin/bash
foo() { bar; baz; bang; biff; bow; }
exit 0

Here's what shellcheck currently says:

$ shellcheck myscript
 
Line 2:
foo() { bar; baz; bang; biff; bow; }
        ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
             ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
                  ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
                        ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
                              ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Here's what I wanted or expected to see:

It's debatable whether this should trigger at all, but clearly there's no reason for this finding to trigger on every command in an unreachable code path. This generates a lot of noise and makes it hard to tell which findings are actionable.

In this case foo is what's actually not being reached, not (just) the individual commands within foo. So it would be even better to flag a case like this as "foo appears unused" rather than "the contents of foo appear unreachable".

@oliv3r
Copy link

oliv3r commented Mar 26, 2023

It's not even correct, is it? It's not an unreachable function, it's an unused function. Which is fine, isn't it?

e.g. if we have a template, that always has a 'pr_info', 'pr_error' function, and in a script, it doesn't have one of those, is that an error? a warning? gcc treats unreachable functions as a warning, this is true, but then we also have the __maybe_unused.

I'm all for telling the user of unreachable codepaths (you did something not so smart, this code can not ever be executed), vs 'you have an unused function'. One is (potentially) an error, the other at the most a warning.

I'd be in favor in splitting these two cases, and probably not even care about unused functions, but at least unused functions (or supporting the '__may_be_unused' flag).

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

2 participants