From: Cuong Manh Le Date: Thu, 30 Nov 2023 17:16:24 +0000 (+0700) Subject: cmd/compile: fix typecheck range over rune literal X-Git-Tag: go1.22rc1~128 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fbfe62bc802d27539a858afd66ae335ff94b1d25;p=gostls13.git cmd/compile: fix typecheck range over rune literal With range over int, the rune literal in range expression will be left as untyped rune, but idealType is not handling this case, causing ICE. Fixing this by setting the concrete type for untyped rune expresison. Fixes #64471 Change-Id: I07a151c54ea1d9e1b92e4d96cdfb6e73dca13862 Reviewed-on: https://go-review.googlesource.com/c/go/+/546296 Reviewed-by: Dmitri Shuralyov Auto-Submit: Cuong Manh Le Reviewed-by: Matthew Dempsky LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/compile/internal/noder/helpers.go b/src/cmd/compile/internal/noder/helpers.go index 1f7b497599..f9e3838fd9 100644 --- a/src/cmd/compile/internal/noder/helpers.go +++ b/src/cmd/compile/internal/noder/helpers.go @@ -99,6 +99,8 @@ func idealType(tv syntax.TypeAndValue) types2.Type { typ = types2.Typ[types2.Bool] // expression in "if" or "for" condition case types2.UntypedString: typ = types2.Typ[types2.String] // argument to "append" or "copy" calls + case types2.UntypedRune: + typ = types2.Typ[types2.Int32] // range over rune default: return nil } diff --git a/test/range3.go b/test/range3.go index 4f770a2b70..f58a398f94 100644 --- a/test/range3.go +++ b/test/range3.go @@ -74,9 +74,17 @@ func testint4() { } } +// Issue #64471. +func testint5() { + for i := range 'a' { + var _ *rune = &i // ensure i has type rune + } +} + func main() { testint1() testint2() testint3() testint4() + testint5() }