Go version
go version go1.26.1 darwin/arm64
Output of go env in your module/workspace:
What did you do?
When inlining (//go:fix inline) code, go fix doesn't account for dot-imports, which results in duplicate imports.
Admitted, dot-imports should generally be avoided, but I noticed this when I tried to simplify my examples for #78164, so thought I'd open a ticket (maybe it's a documentation change only 😅)
What did you see happen?
When inlining (//go:fix inline) code, go fix doesn't account for dot-imports, which results in duplicate imports, for example;
Before:
package main
import . "example.com/client"
func OK() {
opts := []Opt{
FromEnv,
WithLegacyOpt("x"),
WithLegacyOpt2(),
}
c := NewWithOpts(opts...)
c.Create(CreateOpt{Cmd: StrSlice{"top"}})
cmd := StrSlice{"top"}
c.CreateLegacy(CreateOpt{Cmd: cmd})
}
After:
package main
import "example.com/client"
import . "example.com/client"
func OK() {
opts := []Opt{
FromEnv,
client.WithOpt("x"),
client.WithOpt2(),
}
c := client.New(opts...)
c.Create(CreateOpt{Cmd: []string{"top"}})
cmd := []string{"top"}
c.Create(CreateOpt{Cmd: cmd})
}
In case useful, I also attached an example module that I was using for testing; example.zip
What did you expect to see?
I expected either a failure to be reported, or the duplicate import being detected and corrected;
package main
import . "example.com/client"
func OK() {
opts := []Opt{
FromEnv,
WithOpt("x"),
WithOpt2(),
}
c := New(opts...)
c.Create(CreateOpt{Cmd: []string{"top"}})
cmd := []string{"top"}
c.Create(CreateOpt{Cmd: cmd})
}
Go version
go version go1.26.1 darwin/arm64
Output of
go envin your module/workspace:What did you do?
When inlining (
//go:fix inline) code,go fixdoesn't account for dot-imports, which results in duplicate imports.Admitted, dot-imports should generally be avoided, but I noticed this when I tried to simplify my examples for #78164, so thought I'd open a ticket (maybe it's a documentation change only 😅)
What did you see happen?
When inlining (
//go:fix inline) code,go fixdoesn't account for dot-imports, which results in duplicate imports, for example;Before:
After:
In case useful, I also attached an example module that I was using for testing; example.zip
What did you expect to see?
I expected either a failure to be reported, or the duplicate import being detected and corrected;