go/types, types2: remove another coreType call in type checking range clause

For #70128.

Change-Id: I5949bccbfaaebc435ae8ac7c70580d9740de6f00
Reviewed-on: https://go-review.googlesource.com/c/go/+/652136
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2025-02-24 14:47:30 -08:00 committed by Gopher Robot
parent 549a88fa53
commit 7194caf11b
3 changed files with 19 additions and 4 deletions

View File

@ -1040,10 +1040,15 @@ func rangeKeyVal(check *Checker, orig Type, allowVersion func(goVersion) bool) (
}
assert(typ.Recv() == nil)
// check iterator argument type
cb, _ := coreType(typ.Params().At(0).Type()).(*Signature)
var cause2 string
cb, _ := sharedUnder(check, typ.Params().At(0).Type(), &cause2).(*Signature)
switch {
case cb == nil:
return bad("func must be func(yield func(...) bool): argument is not func")
if cause2 != "" {
return bad(check.sprintf("func must be func(yield func(...) bool): in yield type, %s", cause2))
} else {
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 || !Identical(cb.Results().At(0).Type(), universeBool):

View File

@ -1058,10 +1058,15 @@ func rangeKeyVal(check *Checker, orig Type, allowVersion func(goVersion) bool) (
}
assert(typ.Recv() == nil)
// check iterator argument type
cb, _ := coreType(typ.Params().At(0).Type()).(*Signature)
var cause2 string
cb, _ := sharedUnder(check, typ.Params().At(0).Type(), &cause2).(*Signature)
switch {
case cb == nil:
return bad("func must be func(yield func(...) bool): argument is not func")
if cause2 != "" {
return bad(check.sprintf("func must be func(yield func(...) bool): in yield type, %s", cause2))
} else {
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 || !Identical(cb.Results().At(0).Type(), universeBool):

View File

@ -164,6 +164,11 @@ func _[T ~func(func(int) bool)](x T) {
}
}
func _[T func() bool | func(int) bool]() {
for range func /* ERROR "func must be func(yield func(...) bool): in yield type, func() bool and func(int) bool have different underlying types" */ (T) {} {
}
}
// go.dev/issue/65236
func seq0(func() bool) {}