-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.
Milestone
Description
What version of Go are you using (go version
)?
$ go version
gollvm
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env
Debian
Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz (Cascade Lake)
What did you do?
error case:
package main
import "fmt"
func mapscase() int {
one := map[int]int{0: 1299}
two := map[int]int{0: 2388}
x := one
x[0] += func() int {
x = two
return 1113
}()
return two[0]
}
func main() {
a := mapscase()
fmt.Println(a)
}
What did you expect to see?
3501
What did you see instead?
2412
cmd/compile: "x[i] op= y" evaluates x[i] more than once can also be referenced.
Error & Solution
An output of 2412
indicates that x[0] was evaluated twice as follows: once indexing into the old map to read the value 1299, and then once into the new to store the value 1299 + 1113
.
gofrontend doesn't consider such case: when evaluates x twice in "x op= y", evaluating y may affect x. In such case, y on the right should be evaluated first and x on the left should be read latter.
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.