Skip to content

Commit 99001c4

Browse files
cuonglmgopherbot
authored andcommitted
[release-branch.go1.20] cmd/compile: don't set range expr key/value type if already set
Unified IR already records the correct type for them. Fixes #59450 Change-Id: I275c45b48f67bde55c8e2079d60b5868d0acde7f Reviewed-on: https://go-review.googlesource.com/c/go/+/481555 Reviewed-by: Michael Knyszek <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/go/+/482655 Auto-Submit: Michael Knyszek <[email protected]>
1 parent dcc9bdf commit 99001c4

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/cmd/compile/internal/typecheck/stmt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func typecheckrangeExpr(n *ir.RangeStmt) {
7171

7272
do := func(nn ir.Node, t *types.Type) {
7373
if nn != nil {
74-
if ir.DeclaredBy(nn, n) {
74+
if ir.DeclaredBy(nn, n) && nn.Type() == nil {
7575
nn.SetType(t)
7676
} else if nn.Type() != nil {
7777
if op, why := Assignop(t, nn.Type()); op == ir.OXXX {

test/fixedbugs/issue59378.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// compile
2+
3+
// Copyright 2023 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p
8+
9+
func f() {
10+
F([]int{}, func(*int) bool { return true })
11+
}
12+
13+
func F[S []E, E any](a S, fn func(*E) bool) {
14+
for _, v := range a {
15+
G(a, func(e E) bool { return fn(&v) })
16+
}
17+
}
18+
19+
func G[E any](s []E, f func(E) bool) int {
20+
for i, v := range s {
21+
if f(v) {
22+
return i
23+
}
24+
}
25+
return -1
26+
}

0 commit comments

Comments
 (0)