Open
Description
gopls version
.
go env
.
What did you do?
type foo struct {
bar int
}
f := foo{bar: 1}
f.bar = 2 // extract f.bar
What did you see happen?
Currently the produced code has some type error, this messy output happens in any LHS of an assignment:
type foo struct {
bar int
}
f := foo{bar: 1}
xf.bar
f.bar = 2 // extract f.bar
But even we fix the indent/newline format bug, the result would be:
type foo struct {
bar int
}
f := foo{bar: 1}
x := f.bar
x = 2 // semantic different, f.bar remains 1
What did you expect to see?
type foo struct {
bar int
}
f := foo{bar: 1}
x := &f.bar
*x = 2
Reference https://go-review.googlesource.com/c/tools/+/624035/comments/51ffbf6c_61124c11
The crucial point is that any time we extract an addressable expression to a new variable, we may need to extract its address, and replace all uses by *newVar.
Editor and settings
No response
Logs
No response