github.com/JimmyHuang454/JLS-go@v0.0.0-20230831150107-90d536585ba0/internal/types/testdata/fixedbugs/issue41124.go (about) 1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package p 6 7 // Test case from issue. 8 9 type Nat /* ERROR invalid recursive type */ interface { 10 Zero|Succ 11 } 12 13 type Zero struct{} 14 type Succ struct{ 15 Nat // Nat contains type constraints but is invalid, so no error 16 } 17 18 // Struct tests. 19 20 type I1 interface { 21 comparable 22 } 23 24 type I2 interface { 25 ~int 26 } 27 28 type I3 interface { 29 I1 30 I2 31 } 32 33 type _ struct { 34 f I1 // ERROR interface is .* comparable 35 } 36 37 type _ struct { 38 comparable // ERROR interface is .* comparable 39 } 40 41 type _ struct{ 42 I1 // ERROR interface is .* comparable 43 } 44 45 type _ struct{ 46 I2 // ERROR interface contains type constraints 47 } 48 49 type _ struct{ 50 I3 // ERROR interface contains type constraints 51 } 52 53 // General composite types. 54 55 type ( 56 _ [10]I1 // ERROR interface is .* comparable 57 _ [10]I2 // ERROR interface contains type constraints 58 59 _ []I1 // ERROR interface is .* comparable 60 _ []I2 // ERROR interface contains type constraints 61 62 _ *I3 // ERROR interface contains type constraints 63 _ map[I1 /* ERROR interface is .* comparable */ ]I2 // ERROR interface contains type constraints 64 _ chan I3 // ERROR interface contains type constraints 65 _ func(I1 /* ERROR interface is .* comparable */ ) 66 _ func() I2 // ERROR interface contains type constraints 67 ) 68 69 // Other cases. 70 71 var _ = [...]I3 /* ERROR interface contains type constraints */ {} 72 73 func _(x interface{}) { 74 _ = x.(I3 /* ERROR interface contains type constraints */ ) 75 } 76 77 type T1[_ any] struct{} 78 type T3[_, _, _ any] struct{} 79 var _ T1[I2 /* ERROR interface contains type constraints */ ] 80 var _ T3[int, I2 /* ERROR interface contains type constraints */ , float32] 81 82 func f1[_ any]() int { panic(0) } 83 var _ = f1[I2 /* ERROR interface contains type constraints */ ]() 84 func f3[_, _, _ any]() int { panic(0) } 85 var _ = f3[int, I2 /* ERROR interface contains type constraints */ , float32]() 86 87 func _(x interface{}) { 88 switch x.(type) { 89 case I2 /* ERROR interface contains type constraints */ : 90 } 91 }