From: Robert Griesemer Date: Mon, 24 Feb 2025 22:47:30 +0000 (-0800) Subject: go/types, types2: remove another coreType call in type checking range clause X-Git-Tag: go1.25rc1~929 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7194caf11b5b62778618ddb87e5adea5b04654bf;p=gostls13.git 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 Reviewed-by: Robert Griesemer Reviewed-by: Robert Findley Auto-Submit: Robert Griesemer --- diff --git a/src/cmd/compile/internal/types2/stmt.go b/src/cmd/compile/internal/types2/stmt.go index 3f5412fbdd..3cd29fbb4c 100644 --- a/src/cmd/compile/internal/types2/stmt.go +++ b/src/cmd/compile/internal/types2/stmt.go @@ -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): diff --git a/src/go/types/stmt.go b/src/go/types/stmt.go index 5426c5e719..983467e36a 100644 --- a/src/go/types/stmt.go +++ b/src/go/types/stmt.go @@ -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): diff --git a/src/internal/types/testdata/spec/range.go b/src/internal/types/testdata/spec/range.go index 26406fca8a..d77511ece0 100644 --- a/src/internal/types/testdata/spec/range.go +++ b/src/internal/types/testdata/spec/range.go @@ -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) {}