| // errorcheck |
| |
| // Copyright 2023 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 |
| |
| type MyInt int32 |
| type MyBool bool |
| type MyString string |
| |
| type T struct{} |
| |
| func (*T) PM() {} |
| func (T) M() {} |
| |
| func f1() {} |
| func f2(func()) {} |
| func f3(func()) bool { return false } |
| func f4(func(int) bool) bool { return false } |
| func f5(func(int, string) bool) bool { return false } |
| func f6(func(int) bool) {} |
| func f7(func(int) MyBool) MyBool { return false } |
| func f8(func(MyInt, MyString) MyBool) MyBool { return false } |
| |
| func test() { |
| for range T.M { // ERROR "cannot range over T.M \(value of type func\(T\)\): func must have one func argument" |
| } |
| for range (*T).PM { // ERROR "cannot range over \(\*T\).PM \(value of type func\(\*T\)\): func must have one func argument" |
| } |
| for range f1 { // ERROR "cannot range over f1 \(value of type func\(\)\): func must have one func argument" |
| } |
| for range f2 { // ERROR "cannot range over f2 \(value of type func\(func\(\)\)\): func does not return bool" |
| } |
| for range f3 { // ERROR "cannot range over f3 \(value of type func\(func\(\)\) bool\): callback does not return bool" |
| } |
| for range f4 { |
| } |
| for range f5 { |
| } |
| for range f6 { // ERROR "cannot range over f6 \(value of type func\(func\(int\) bool\)\): func does not return bool" |
| } |
| for range f7 { |
| } |
| for range f8 { |
| } |
| for range 1 { |
| } |
| for range uint8(1) { |
| } |
| for range int64(1) { |
| } |
| for range MyInt(1) { |
| } |
| for range 'x' { |
| } |
| for range 1.0 { // ERROR "cannot range over 1.0 \(untyped float constant 1\)" |
| } |
| |
| var i int |
| var s string |
| var mi MyInt |
| var ms MyString |
| for i := range f4 { |
| _ = i |
| } |
| for i = range f4 { |
| _ = i |
| } |
| for i, s := range f5 { |
| _, _ = i, s |
| } |
| for i, s = range f5 { |
| _, _ = i, s |
| } |
| for i := range f5 { |
| _ = i |
| } |
| for i = range f5 { |
| _ = i |
| } |
| for i := range f7 { |
| _ = i |
| } |
| for i = range f7 { |
| _ = i |
| } |
| for mi := range f8 { |
| _ = mi |
| } |
| for mi = range f8 { |
| _ = mi |
| } |
| for mi, ms := range f8 { |
| _, _ = mi, ms |
| } |
| for mi, ms = range f8 { |
| _, _ = mi, ms |
| } |
| |
| for i := range 10 { |
| _ = i |
| } |
| for i = range 10 { |
| _ = i |
| } |
| for i, j := range 10 { // ERROR "range over 10 \(untyped int constant\) permits only one iteration variable" |
| _, _ = i, j |
| } |
| for mi := range MyInt(10) { |
| _ = mi |
| } |
| for mi = range MyInt(10) { |
| _ = mi |
| } |
| } |