aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2024-02-02 09:35:07 +0700
committerGopher Robot <gobot@golang.org>2024-02-20 22:29:14 +0000
commit5428cc4f148bec34987781137ccd30494a99ad15 (patch)
treeaca41e0e943051150d922ae1441a64b2aae504c3 /test
parent53708d86b076b7295e93e49b7a19ac7d9082044f (diff)
downloadgo-5428cc4f148bec34987781137ccd30494a99ad15.tar.gz
go-5428cc4f148bec34987781137ccd30494a99ad15.zip
cmd/compile/internal/typecheck: remove constant bounds check
types2 handles all constant-related bounds checks in user Go code now, so it's safe to remove the check from typecheck, avoid the inconsistency with type parameter. Fixes #65417 Change-Id: I82dd197b78e271725d132b5a20450ae3e90f9abc Reviewed-on: https://go-review.googlesource.com/c/go/+/560575 Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue65417.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/fixedbugs/issue65417.go b/test/fixedbugs/issue65417.go
new file mode 100644
index 0000000000..15e84d819c
--- /dev/null
+++ b/test/fixedbugs/issue65417.go
@@ -0,0 +1,42 @@
+// run
+
+// Copyright 2024 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
+
+import (
+ "strings"
+ "unsafe"
+)
+
+func main() {
+ shouldPanic("runtime error: index out of range", func() { f(0) })
+ shouldPanic("runtime error: index out of range", func() { g(0) })
+}
+
+func f[T byte](t T) {
+ const str = "a"
+ _ = str[unsafe.Sizeof(t)]
+}
+
+func g[T byte](t T) {
+ const str = "a"
+ _ = str[unsafe.Sizeof(t)+0]
+}
+
+func shouldPanic(str string, f func()) {
+ defer func() {
+ err := recover()
+ if err == nil {
+ panic("did not panic")
+ }
+ s := err.(error).Error()
+ if !strings.Contains(s, str) {
+ panic("got panic " + s + ", want " + str)
+ }
+ }()
+
+ f()
+}