return bad("func must be func(yield func(...) bool): argument is not func")
case cb.Params().Len() > 2:
return bad("func must be func(yield func(...) bool): yield func has too many parameters")
- case cb.Results().Len() != 1 || !isBoolean(cb.Results().At(0).Type()):
- return bad("func must be func(yield func(...) bool): yield func does not return bool")
+ case cb.Results().Len() != 1 || !Identical(cb.Results().At(0).Type(), universeBool):
+ // see go.dev/issues/71131, go.dev/issues/71164
+ if cb.Results().Len() == 1 && isBoolean(cb.Results().At(0).Type()) {
+ return bad("func must be func(yield func(...) bool): yield func returns user-defined boolean, not bool")
+ } else {
+ return bad("func must be func(yield func(...) bool): yield func does not return bool")
+ }
}
assert(cb.Recv() == nil)
// determine key and value types, if any
var (
universeIota Object
+ universeBool Type
universeByte Type // uint8 alias, but has name "byte"
universeRune Type // int32 alias, but has name "rune"
universeAnyNoAlias *TypeName
defPredeclaredFuncs()
universeIota = Universe.Lookup("iota")
+ universeBool = Universe.Lookup("bool").Type()
universeByte = Universe.Lookup("byte").Type()
universeRune = Universe.Lookup("rune").Type()
universeError = Universe.Lookup("error").Type()
return bad("func must be func(yield func(...) bool): argument is not func")
case cb.Params().Len() > 2:
return bad("func must be func(yield func(...) bool): yield func has too many parameters")
- case cb.Results().Len() != 1 || !isBoolean(cb.Results().At(0).Type()):
- return bad("func must be func(yield func(...) bool): yield func does not return bool")
+ case cb.Results().Len() != 1 || !Identical(cb.Results().At(0).Type(), universeBool):
+ // see go.dev/issues/71131, go.dev/issues/71164
+ if cb.Results().Len() == 1 && isBoolean(cb.Results().At(0).Type()) {
+ return bad("func must be func(yield func(...) bool): yield func returns user-defined boolean, not bool")
+ } else {
+ return bad("func must be func(yield func(...) bool): yield func does not return bool")
+ }
}
assert(cb.Recv() == nil)
// determine key and value types, if any
var (
universeIota Object
+ universeBool Type
universeByte Type // uint8 alias, but has name "byte"
universeRune Type // int32 alias, but has name "rune"
universeAnyNoAlias *TypeName
defPredeclaredFuncs()
universeIota = Universe.Lookup("iota")
+ universeBool = Universe.Lookup("bool").Type()
universeByte = Universe.Lookup("byte").Type()
universeRune = Universe.Lookup("rune").Type()
universeError = Universe.Lookup("error").Type()
--- /dev/null
+// 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) {} {
+ }
+}
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