Skip to content

Missing "cannot be declared & assigned separately" error when using local -r #2362

@vincentcr

Description

@vincentcr

For bugs

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

#!/bin/bash

myfunc() {
 local -r x=$(false)
}

Here's what shellcheck currently says:

nothing

Here's what I wanted or expected to see:

I expected the error SC2155: Declare and assign separately to avoid masking return values..

This is very subtle mistake to make which can lead to really bad outcomes if you're relying on your script to stop executing on errors. shellcheck is critical to avoid the various pitfalls, and it's too bad that this one is left behind intentionally.

I realize that the doc mentions this case explicitly, but I am perplexed at the justification. I'm sure I'm far from the only person who prefers a little verbosity to incorrect code. Especially since this behavior is untunable and totally silent unless you actually stumble on the issue and notice it.

I understand why some people would prefer a "relaxed/not annoying" version of shellcheck, but it seems to me this ought to be tunable so you are aware of the consequences.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions