Closed danutavadanei closed 2 years ago
Arguments to a deferred function call are evaluated at the defer
statement. Your assignment to err
doesn't have the effect that you think
it does.
On Fri, Jun 17, 2022, 11:52 Danut Avadanei @.***> wrote:
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
— Reply to this email directly, view it on GitHub https://github.com/gordonklaus/ineffassign/issues/71, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMP7UATJ36VZX4ZDT54NSDVPRDE3ANCNFSM5ZBXP5SQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Got it, thanks! Fixed my code with defer func() { shutdown(err) }()
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
Expectation: should not reported.
Output