3 // Copyright 2023 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
12 type MyFunc1 func(func(int) bool)
13 type MyFunc2 func(int) bool
14 type MyFunc3 func(MyFunc2)
23 func f4(func(int) bool) {}
24 func f5(func(int, string) bool) {}
25 func f7(func(int) MyBool) {}
26 func f8(func(MyInt, MyString) MyBool) {}
29 // TODO: Would be nice to 'for range T.M' and 'for range (*T).PM' directly,
30 // but there is no gofmt-friendly way to write the error pattern in the right place.
32 for range m1 /* ERROR "cannot range over m1 (variable of type func(T)): func must be func(yield func(...) bool): argument is not func" */ {
35 for range m2 /* ERROR "cannot range over m2 (variable of type func(*T)): func must be func(yield func(...) bool): argument is not func" */ {
37 for range f1 /* ERROR "cannot range over f1 (value of type func()): func must be func(yield func(...) bool): wrong argument count" */ {
39 for range f2 /* ERROR "cannot range over f2 (value of type func(func())): func must be func(yield func(...) bool): yield func does not return bool" */ {
41 for range f4 /* ERROR "range over f4 (value of type func(func(int) bool)) must have one iteration variable" */ {
61 for range 1.0 /* ERROR "cannot range over 1.0 (untyped float constant 1)" */ {
63 for _ = range MyFunc1(nil) {
65 for _ = range MyFunc3(nil) {
67 for _ = range (func(MyFunc2))(nil) {
80 for i, s := range f5 {
86 for i, _ := range f5 {
98 for mi, _ := range f8 {
101 for mi, _ = range f8 {
104 for mi, ms := range f8 {
107 for i /* ERROR "cannot use i (value of type MyInt) as int value in assignment" */, s /* ERROR "cannot use s (value of type MyString) as string value in assignment" */ = range f8 {
110 for mi, ms := range f8 {
111 i, s = mi /* ERROR "cannot use mi (variable of type MyInt) as int value in assignment" */, ms /* ERROR "cannot use ms (variable of type MyString) as string value in assignment" */
113 for mi, ms = range f8 {
123 for i, j /* ERROR "range over 10 (untyped int constant) permits only one iteration variable" */ := range 10 {
126 for mi := range MyInt(10) {
129 for mi = range MyInt(10) {
134 func _[T int | string](x T) {
135 for range x /* ERROR "cannot range over x (variable of type T constrained by int | string): no core type" */ {
139 func _[T int | int64](x T) {
140 for range x /* ERROR "cannot range over x (variable of type T constrained by int | int64): no core type" */ {
144 func _[T ~int](x T) {
149 func _[T any](x func(func(T) bool)) {
150 for _ = range x { // ok
154 func _[T ~func(func(int) bool)](x T) {
155 for _ = range x { // ok