Skip to content

x/tools/gopls: refactor.rewrite.eliminateDotImport breaks keyed struct literals #73960

Closed
@dominikh

Description

@dominikh

gopls version

Build info

golang.org/x/tools/gopls v0.1.8-0.20250603152015-25caa76c0f39+dirty
golang.org/x/tools/[email protected]+dirty
github.com/BurntSushi/[email protected] h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
github.com/fatih/[email protected] h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
github.com/fatih/[email protected] h1:dDSgAjoOMp8da3egfz0t2S+t8RGOpEmEXZubcGuc0Bg=
github.com/fatih/[email protected] h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/[email protected] h1:Br3+0EZZohShrmVVc85znGpxw7Ca8hsUJlrdT/JQGw8=
golang.org/x/[email protected] h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
golang.org/x/[email protected] h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
golang.org/x/[email protected] h1:RXY2+rSHXvxO2Y+gKrPjYVaEoGOqh3VEXFhnWAt1Irg=
golang.org/x/[email protected] h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
golang.org/x/[email protected] => ../
golang.org/x/[email protected] h1:Ju8QsuyhX3Hk8ma3CesTbO8vfJD9EvUBgHvkxHBzj0I=
honnef.co/go/[email protected] h1:fj8r9irJSpolAGUdZBxJIRY3lLc4jH2Dt4lwnWyWwpw=
mvdan.cc/[email protected] h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=
mvdan.cc/xurls/[email protected] h1:3NTZpeTxYVWNSokW3MKeyVkz/j7uYXYiMtXRUfmjbgI=
go: go1.25-devel_ed08d2ad09 Tue May 27 19:35:07 2025 -0700

go env

-

What did you do?

$ txtar .
-- bar/bar.go --
package bar

import . "example.com/foo"

func fn() {
	_ = Foo{
		Field: "",
	}
}
-- foo/foo.go --
package foo

type Foo struct {
	Field string
}
-- go.mod --
module example.com

go 1.25
$ gopls codeaction -kind=refactor.rewrite.eliminateDotImport -exec -diff ./bar/bar.go:3:8

What did you see happen?

The action rewrites the field names in keyed literals.

--- /home/dominikh/prj/src/example.com/bar/bar.go.orig
+++ /home/dominikh/prj/src/example.com/bar/bar.go
@@ -1,9 +1,9 @@
 package bar
 
-import . "example.com/foo"
+import "example.com/foo"
 
 func fn() {
-	_ = Foo{
+	_ = foo.Foo{
-		Field: "",
+		foo.Field: "",
 	}
 }

What did you expect to see?

It shouldn't rewrite the field names in keyed literals.

Editor and settings

No response

Logs

No response

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions