1 // Copyright 2017 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 import "unsafe"
8
9 // test case from issue #18395
10
11 type (
12 A interface { B }
13 B interface { C }
14 C interface { D; F() A }
15 D interface { G() B }
16 )
17
18 var _ = A(nil).G // G must be found
19
20
21 // test case from issue #21804
22
23 type sourceBridge interface {
24 listVersions() ([]Version, error)
25 }
26
27 type Constraint interface {
28 copyTo(*ConstraintMsg)
29 }
30
31 type ConstraintMsg struct{}
32
33 func (m *ConstraintMsg) asUnpairedVersion() UnpairedVersion {
34 return nil
35 }
36
37 type Version interface {
38 Constraint
39 }
40
41 type UnpairedVersion interface {
42 Version
43 }
44
45 var _ Constraint = UnpairedVersion(nil)
46
47
48 // derived test case from issue #21804
49
50 type (
51 _ interface{ m(B1) }
52 A1 interface{ a(D1) }
53 B1 interface{ A1 }
54 C1 interface{ B1 }
55 D1 interface{ C1 }
56 )
57
58 var _ A1 = C1(nil)
59
60
61 // derived test case from issue #22701
62
63 func F(x I4) interface{} {
64 return x.Method()
65 }
66
67 type Unused interface {
68 RefersToI1(a I1)
69 }
70
71 type I1 interface {
72 I2
73 I3
74 }
75
76 type I2 interface {
77 RefersToI4() I4
78 }
79
80 type I3 interface {
81 Method() interface{}
82 }
83
84 type I4 interface {
85 I1
86 }
87
88
89 // check embedding of error interface
90
91 type Error interface{ error }
92
93 var err Error
94 var _ = err.Error()
95
96
97 // more esoteric cases
98
99 type (
100 T1 interface { T2 }
101 T2 /* ERROR cycle */ T2
102 )
103
104 type (
105 T3 interface { T4 }
106 T4 /* ERROR cycle */ T5
107 T5 = T6
108 T6 = T7
109 T7 = T4
110 )
111
112
113 // arbitrary code may appear inside an interface
114
115 const n = unsafe.Sizeof(func(){})
116
117 type I interface {
118 m([unsafe.Sizeof(func() { I.m(nil, [n]byte{}) })]byte)
119 }
120
121
122 // test cases for varias alias cycles
123
124 type T10 /* ERROR cycle */ = *T10 // issue #25141
125 type T11 /* ERROR cycle */ = interface{ f(T11) } // issue #23139
126
127 // issue #18640
128 type (
129 aa = bb
130 bb struct {
131 *aa
132 }
133 )
134
135 type (
136 a struct{ *b }
137 b = c
138 c struct{ *b /* ERROR invalid use of type alias */ }
139 )
140
141 // issue #24939
142 type (
143 _ interface {
144 M(P)
145 }
146
147 M interface {
148 F() P // ERROR invalid use of type alias
149 }
150
151 P = interface {
152 I() M
153 }
154 )
155
156 // issue #8699
157 type T12 /* ERROR cycle */ [len(a12)]int
158 var a12 = makeArray()
159 func makeArray() (res T12) { return }
160
161 // issue #20770
162 var r /* ERROR cycle */ = newReader()
163 func newReader() r
164
165 // variations of the theme of #8699 and #20770
166 var arr /* ERROR cycle */ = f()
167 func f() [len(arr)]int
168
169 // issue #25790
170 func ff(ff /* ERROR not a type */ )
171 func gg((gg /* ERROR not a type */ ))
172
173 type T13 /* ERROR cycle */ [len(b13)]int
174 var b13 T13
175
176 func g1() [unsafe.Sizeof(g1)]int
177 func g2() [unsafe.Sizeof(x2)]int
178 var x2 = g2
179
180 // verify that we get the correct sizes for the functions above
181 // (note: assert is statically evaluated in go/types test mode)
182 func init() {
183 assert(unsafe.Sizeof(g1) == 8)
184 assert(unsafe.Sizeof(x2) == 8)
185 }
186
187 func h() [h /* ERROR no value */ ()[0]]int { panic(0) }
188
189 var c14 /* ERROR cycle */ T14
190 type T14 [uintptr(unsafe.Sizeof(&c14))]byte
191
192 // issue #34333
193 type T15 /* ERROR cycle */ struct {
194 f func() T16
195 b T16
196 }
197
198 type T16 struct {
199 T15
200 }
View as plain text