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

"Ineffectual assignment" false positive when var used in deferred function call #71

Closed
danutavadanei opened this issue Jun 17, 2022 · 2 comments

Comments

@danutavadanei
Copy link

ineffassign version: last version available
go version: go version go1.18.3

Running the linter when interacting with a var after passing it to a deferred function call marks it as ineffectual assignment

package main

import "errors"

func shutdown(err error) {
    if err != nil {
        panic(err)
    }
}

func TestLint() {
    var err error
    defer shutdown(err)

    if true {
        err = errors.New("new error message") // test.go:16:9: ineffectual assignment to err
    }
}

Expectation: should not reported.

Output

ineffassign ./...
go-lint-issue/cmd/test.go:16:9: ineffectual assignment to err
@gordonklaus
Copy link
Owner

gordonklaus commented Jun 17, 2022 via email

@danutavadanei
Copy link
Author

Got it, thanks! Fixed my code with defer func() { shutdown(err) }()

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