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/gopls: extract(refactor) fails on anonymous structs #61496

Open
KrzysztofJopek opened this issue Jul 21, 2023 · 1 comment
Open

x/tools/gopls: extract(refactor) fails on anonymous structs #61496

KrzysztofJopek opened this issue Jul 21, 2023 · 1 comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@KrzysztofJopek
Copy link

What version of Go are you using (go version)?

go version go1.20.6 darwin/amd64

golang.org/x/tools/gopls v0.12.4
    golang.org/x/tools/gopls@(devel)

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

darwin, amd64

What did you expect to see?

Refactor of code with anonymous struct completes successfully

What did you see instead?

parent nil error while extracting code with anonymous struct
I was able to reproduce the issue in both Neovim and VSCode.

On the demo below, you can see a successful refactor of named struct and then fail on anonymous struct.
https://github.com/golang/go/assets/27726430/f3096917-4158-4bf1-be52-4477863fa454

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jul 21, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jul 21, 2023
@adonovan
Copy link
Member

adonovan commented Jul 25, 2023

Thanks for the bug report. I can reproduce it using the testcase below.

It includes a test case for a second bug that was obvious from inspection of the code, which not only doesn't distinguish local vars from field vars, but doesn't distinguish vars from types.

I suspect the fix will be more involved that we have time for at the moment.

$ cat  gopls/internal/regtest/marker/testdata/codeaction/extract_issue61496.txt
This test verifies extraction of a function
whose parameters include anonymous struct types.
It is a regression test for issue #61496.

-- go.mod --
module testdata
go 1.18

-- a.go --
package testdata

func _() {
	var x struct { y int }	//@ codeaction("refactor.extract", "var", end, anon)
	println(x.y)		//@ loc(end, ")")
}

-- @anon/a.go --
xxx

-- @localtype/b.go --
package testdata

func _() {
        type T int 
	var x T 		//@ codeaction("refactor.extract", "var", end, anon)
	println(x.y)		//@ loc(end, ")")
}

-- @localtype/b.go --
xxx

@adonovan adonovan modified the milestones: Unreleased, gopls/later Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants