Debian Codegraph @

test/typeparam/issue48962.dir/b.go

raw
1 // Copyright 2022 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 b
6
7 import "./a"
8
9 type (
10 lA[P any] [10]P
11 lS[P any] struct{ f P }
12 lP[P any] *P
13 lM[K comparable, V any] map[K]V
14 )
15
16 // local cycles
17 type (
18 A lA[A] // ERROR "invalid recursive type"
19 S lS[S] // ERROR "invalid recursive type"
20 P lP[P] // ok (indirection through lP)
21 M1 lM[int, M1] // ok (indirection through lM)
22 M2 lM[lA[byte], M2] // ok (indirection through lM)
23
24 A2 lA[lS[lP[A2]]] // ok (indirection through lP)
25 A3 lA[lS[lS[A3]]] // ERROR "invalid recursive type"
26 )
27
28 // cycles through imported types
29 type (
30 Ai a.A[Ai] // ERROR "invalid recursive type"
31 Si a.S[Si] // ERROR "invalid recursive type"
32 Pi a.P[Pi] // ok (indirection through a.P)
33 M1i a.M[int, M1i] // ok (indirection through a.M)
34 M2i a.M[a.A[byte], M2i] // ok (indirection through a.M)
35
36 A2i a.A[a.S[a.P[A2i]]] // ok (indirection through a.P)
37 A3i a.A[a.S[a.S[A3i]]] // ERROR "invalid recursive type"
38
39 T2 a.S[T0[T2]] // ERROR "invalid recursive type"
40 T3 T0[Ai] // no follow-on error here
41 )
42
43 // test case from issue
44
45 type T0[P any] struct {
46 f P
47 }
48
49 type T1 struct { // ERROR "invalid recursive type"
50 _ T0[T1]
51 }