aboutsummaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2025-01-07 15:06:05 -0800
committerGopher Robot <gobot@golang.org>2025-01-08 13:54:54 -0800
commitc9afcbade7308cf66b67b9ce080f10b621b17c6a (patch)
tree03d9b4554bc3bb39f72746a82775ef8fe6f3a5fe /src/internal
parent54693a81fd605a9c1abbee83da072c61e38d3ebf (diff)
downloadgo-c9afcbade7308cf66b67b9ce080f10b621b17c6a.tar.xz
go/types, types2: require iterator yield to return bool (work-around)
The original implementation of the type checkers accepted any boolean result type for yield, but the compiler's front-end had a problem with it (#71131). As a temporary fix (for 1.24), adjust the type checkers to insist on the spec's literal wording and avoid the compiler panic. Fixes #71131. For #71164. Change-Id: Ie25f9a892e58b5e489d399b0bce2d0af55dc3c48 Reviewed-on: https://go-review.googlesource.com/c/go/+/640599 Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Tim King <taking@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/types/testdata/fixedbugs/issue71131.go15
-rw-r--r--src/internal/types/testdata/spec/range.go2
2 files changed, 16 insertions, 1 deletions
diff --git a/src/internal/types/testdata/fixedbugs/issue71131.go b/src/internal/types/testdata/fixedbugs/issue71131.go
new file mode 100644
index 0000000000..8e7575b028
--- /dev/null
+++ b/src/internal/types/testdata/fixedbugs/issue71131.go
@@ -0,0 +1,15 @@
+// Copyright 2025 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 p
+
+func _() {
+ type Bool bool
+ for range func /* ERROR "yield func returns user-defined boolean, not bool" */ (func() Bool) {} {
+ }
+ for range func /* ERROR "yield func returns user-defined boolean, not bool" */ (func(int) Bool) {} {
+ }
+ for range func /* ERROR "yield func returns user-defined boolean, not bool" */ (func(int, string) Bool) {} {
+ }
+}
diff --git a/src/internal/types/testdata/spec/range.go b/src/internal/types/testdata/spec/range.go
index 52d1e70382..c0f579479f 100644
--- a/src/internal/types/testdata/spec/range.go
+++ b/src/internal/types/testdata/spec/range.go
@@ -5,7 +5,7 @@
package p
type MyInt int32
-type MyBool bool
+type MyBool = bool // TODO(gri) remove alias declaration - see go.dev/issues/71131, go.dev/issues/71164
type MyString string
type MyFunc1 func(func(int) bool)
type MyFunc2 func(int) bool