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