aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2023-10-05 11:11:51 +0700
committerGopher Robot <gobot@golang.org>2023-10-09 18:09:34 +0000
commit778880b00888066212864f95877c0febbebf7e69 (patch)
treeb1e315e14f31cc4f8cbacacc3c4d35fb14b0d04d /test
parentede27fb4aca9ab103413aff71b254f10db2b302a (diff)
downloadgo-778880b00888066212864f95877c0febbebf7e69.tar.gz
go-778880b00888066212864f95877c0febbebf7e69.zip
cmd/compile: fix typecheck range over negative integer
Before range over integer, types2 leaves constant expression in RHS of non-constant shift untyped, so idealType do the validation to ensure that constant value must be an int >= 0. With range over int, the range expression can also be left untyped, and can be an negative integer, causing the validation false. Fixing this by relaxing the validation in idealType, and moving the check to Unified IR reader. Fixes #63378 Change-Id: I43042536c09afd98d52c5981adff5dbc5e7d882a Reviewed-on: https://go-review.googlesource.com/c/go/+/532835 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test')
-rw-r--r--test/range3.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/range3.go b/test/range3.go
index 613d7a53f6..51ed2eeb78 100644
--- a/test/range3.go
+++ b/test/range3.go
@@ -68,6 +68,14 @@ func testint3() {
}
}
+// Issue #63378.
+func testint4() {
+ for i := range -1 {
+ _ = i
+ panic("must not be executed")
+ }
+}
+
// test range over functions
var gj int
@@ -377,6 +385,7 @@ func main() {
testint1()
testint2()
testint3()
+ testint4()
testfunc0()
testfunc1()
testfunc2()