diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/compile/internal/types2/range.go | 3 | ||||
| -rw-r--r-- | src/go/types/range.go | 3 | ||||
| -rw-r--r-- | src/internal/types/testdata/fixedbugs/issue78483.go | 15 |
3 files changed, 21 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types2/range.go b/src/cmd/compile/internal/types2/range.go index ae6524d0e4..f7ecbb4c76 100644 --- a/src/cmd/compile/internal/types2/range.go +++ b/src/cmd/compile/internal/types2/range.go @@ -240,6 +240,7 @@ func rangeKeyVal(check *Checker, orig Type, allowVersion func(goVersion) bool) ( return bad("requires go1.23 or later") } // check iterator arity + // TODO(gri) error messages could be less verbose (consider rangeStmt error and cause returned here) switch { case typ.Params().Len() != 1: return bad("func must be func(yield func(...) bool): wrong argument count") @@ -266,6 +267,8 @@ func rangeKeyVal(check *Checker, orig Type, allowVersion func(goVersion) bool) ( } else { return bad("func must be func(yield func(...) bool): yield func does not return bool") } + case cb.Variadic(): + return bad(check.sprintf("yield func of type %s cannot be variadic", cb)) } assert(cb.Recv() == nil) // determine key and value types, if any diff --git a/src/go/types/range.go b/src/go/types/range.go index 208da64ba2..8eceb4d787 100644 --- a/src/go/types/range.go +++ b/src/go/types/range.go @@ -243,6 +243,7 @@ func rangeKeyVal(check *Checker, orig Type, allowVersion func(goVersion) bool) ( return bad("requires go1.23 or later") } // check iterator arity + // TODO(gri) error messages could be less verbose (consider rangeStmt error and cause returned here) switch { case typ.Params().Len() != 1: return bad("func must be func(yield func(...) bool): wrong argument count") @@ -269,6 +270,8 @@ func rangeKeyVal(check *Checker, orig Type, allowVersion func(goVersion) bool) ( } else { return bad("func must be func(yield func(...) bool): yield func does not return bool") } + case cb.Variadic(): + return bad(check.sprintf("yield func of type %s cannot be variadic", cb)) } assert(cb.Recv() == nil) // determine key and value types, if any diff --git a/src/internal/types/testdata/fixedbugs/issue78483.go b/src/internal/types/testdata/fixedbugs/issue78483.go new file mode 100644 index 0000000000..7f4bc01e22 --- /dev/null +++ b/src/internal/types/testdata/fixedbugs/issue78483.go @@ -0,0 +1,15 @@ +// Copyright 2026 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 _() { + for range f1 /* ERROR "cannot range over f1 (value of type func(func(...int) bool)): yield func of type func(...int) bool cannot be variadic" */ { + } + for range f2 /* ERROR "cannot range over f2 (value of type func(func(int, ...int) bool)): yield func of type func(int, ...int) bool cannot be variadic" */ { + } +} + +func f1(func(...int) bool) {} +func f2(func(int, ...int) bool) {} |
