0
1
mirror of https://github.com/golang/go synced 2025-05-29 15:20:52 +00:00

[release-branch.go1.19] cmd/compile: fix ir.StaticValue for ORANGE

Range statement will mutate the key and value, so we should treat them as reassigned.

Fixes 

Change-Id: I9c6b67d938760a0c6a1d9739f2737c67af4a3a10
Reviewed-on: https://go-review.googlesource.com/c/go/+/483855
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
(cherry picked from commit 89567a35c1)
Reviewed-on: https://go-review.googlesource.com/c/go/+/484135
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Junwei Zuo
2023-04-12 18:53:51 +08:00
committed by Matthew Dempsky
parent 22c1d18a27
commit abb86e6e82
3 changed files with 38 additions and 0 deletions
src/cmd/compile/internal/ir
test/fixedbugs

@ -912,6 +912,11 @@ func reassigned(name *Name) bool {
if isName(OuterValue(n.X)) {
return true
}
case ORANGE:
n := n.(*RangeStmt)
if isName(n.Key) || isName(n.Value) {
return true
}
case OCLOSURE:
n := n.(*ClosureExpr)
if Any(n.Func, do) {

@ -0,0 +1,30 @@
// run
// Copyright 2023 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.
package main
func foo() {
println("foo")
}
func main() {
fn := foo
for _, fn = range list {
fn()
}
}
var list = []func(){
func() {
println("1")
},
func() {
println("2")
},
func() {
println("3")
},
}

@ -0,0 +1,3 @@
1
2
3