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

x/tools/internal/refactor/inline: unnecessary (&y).f after inlining function containing x.f() call to method declared as (*T).f #69442

Closed
lfolger opened this issue Sep 13, 2024 · 3 comments
Assignees
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@lfolger
Copy link
Contributor

lfolger commented Sep 13, 2024

func TestPointerReceiver(t *testing.T) {
	files := map[string]string{
					package foo
				type T int

				func (*T) F() {}

				//inlineme
				func (t *T) G() { t.F() }

				func main() {
					var t T
					t.G() // want "inline call of (*fooT).G"
				}
		`,
		"foo/foo.go.golden": `
			package foo
				type T int

				func (*T) F() {}

				//inlineme
				func (t *T) G() { t.F() }

				func main() {
					var t T
					t.F() // want "inline call of (*fooT).G"
				}
		`,
	}
	dir, cleanup, err := analysistest.WriteFiles(files)
	if err != nil {
		t.Fatal(err)
	}
	analysistest.RunWithSuggestedFixes(t, dir, analyzer.Analyzer, "foo")
	cleanup()
}

The test fails with:

        --- .../foo/foo.go.golden
        +++ actual
        @@ -9,5 +9,5 @@

         func main() {
                var t T
        -       t.F() // want `inline call of \(\*foo.T\).G`
        +       (&t).F() // want `inline call of \(\*foo.T\).G`
         }

I would be great if the inliner could just not add the unnecessary syntax although it is possible that I'm missing and edge case and this is actually needed.

@lfolger lfolger added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 13, 2024
@gopherbot gopherbot added this to the Unreleased milestone Sep 13, 2024
@gabyhelp
Copy link

@lfolger
Copy link
Contributor Author

lfolger commented Sep 13, 2024

cc: @findleyr @adonovan @stapelberg

@timothy-king timothy-king added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 13, 2024
@adonovan adonovan added the Refactoring Issues related to refactoring tools label Sep 17, 2024
@adonovan adonovan changed the title x/tools/internal/refactor/inline: adds unnecessary when inlining pointer receiver function calls on non-pointer values x/tools/internal/refactor/inline: unnecessary (&y).f after inlining function containing x.f() method declared as (*T).f Nov 5, 2024
@adonovan adonovan changed the title x/tools/internal/refactor/inline: unnecessary (&y).f after inlining function containing x.f() method declared as (*T).f x/tools/internal/refactor/inline: unnecessary (&y).f after inlining function containing x.f() call to method declared as (*T).f Nov 5, 2024
@findleyr findleyr self-assigned this Nov 21, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/630855 mentions this issue: internal/refactor/inline: avoid unnecessary desugaring in selectors

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.17.0 Nov 22, 2024
@findleyr findleyr added the FixPending Issues that have a fix which has not yet been reviewed or submitted. label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

6 participants