mirror of
https://github.com/golang/go
synced 2024-11-11 19:51:37 -07:00
92bb694a49
The change in 20907 fixed varexpr but broke aliased. After that change, a reference to a field in a struct would not be seen as aliasing itself. Before that change, it would, but only because all fields in a struct aliased everything. This CL changes the compiler to consider all references to a field as aliasing all other fields in that struct. This is imperfect--a reference to one field does not alias another field--but is a simple fix for the immediate problem. A better fix would require tracking the specific fields as well. Fixes #15042. Change-Id: I5c95c0dd7b0699e53022fce9bae2e8f50d6d1d04 Reviewed-on: https://go-review.googlesource.com/21390 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
28 lines
451 B
Go
28 lines
451 B
Go
// run
|
|
|
|
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Exchanging two struct fields was compiled incorrectly.
|
|
|
|
package main
|
|
|
|
type S struct {
|
|
i int
|
|
}
|
|
|
|
func F(c bool, s1, s2 S) (int, int) {
|
|
if c {
|
|
s1.i, s2.i = s2.i, s1.i
|
|
}
|
|
return s1.i, s2.i
|
|
}
|
|
|
|
func main() {
|
|
i, j := F(true, S{1}, S{20})
|
|
if i != 20 || j != 1 {
|
|
panic(i+j)
|
|
}
|
|
}
|