golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.68k stars 17.49k forks source link

x/tools/gopls: unnecessary eta abstraction while removing parameter #65217

Open findleyr opened 7 months ago

findleyr commented 7 months ago

In CL 557496, we observed that removing an unused parameter resulted in an unnecessary eta abstraction:

From:

rewrites, err := getRewriteCodeActions(snapshot, pkg, pgf, fh, rng, snapshot.Options())

To:

rewrites, err := func() (_ []protocol.CodeAction, rerr error) {
    var options *settings.Options = snapshot.Options()
    return getRewriteCodeActions(pkg, pgf, fh, rng, options)
}()

In this case, I'm sure it's the effect detection that triggers the literalization, but that's not correct. There is no change in effects before and after the parameter is removed, since the unused parameter has no side effects.

This is probably an artifact of how parameter removal is implemented via inlined wrappers.

CC @adonovan @suzmue

gopherbot commented 4 months ago

Change https://go.dev/cl/580835 mentions this issue: internal/refactor/inline: remove eta abstraction inlining assignments