Debian Codegraph @

src/internal/types/testdata/check/cycles6.go

raw
1 // Copyright 2026 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 // Below are the pieces of syntax corresponding to functions which can produce a
10 // type T without first having a value of type T. Notice that each causes a
11 // value of type T to be passed to unsafe.Sizeof while T is incomplete.
12
13 // literal on type
14 type T0 /* ERROR "invalid recursive type" */ [unsafe.Sizeof(T0{})]int
15 // literal on value (not applicable)
16 // literal on pointer (not applicable)
17
18 // call on type
19 type T1 /* ERROR "invalid recursive type" */ [unsafe.Sizeof(T1(42))]int
20 // call on value
21 func f2() T2
22 type T2 /* ERROR "invalid recursive type" */ [unsafe.Sizeof(f2())]int
23 // call on pointer (not applicable)
24
25 // assert on type
26 var i3 interface{}
27 type T3 /* ERROR "invalid recursive type" */ [unsafe.Sizeof(i3.(T3))]int
28 // assert on value (not applicable)
29 // assert on pointer (not applicable)
30
31 // receive on type (not applicable)
32 // receive on value
33 func f4() <-chan T4
34 type T4 /* ERROR "invalid recursive type" */ [unsafe.Sizeof(<-f4())]int
35 // receive on pointer (not applicable)
36
37 // star on type (not applicable)
38 // star on value (not applicable)
39 // star on pointer
40 func f5() *T5
41 type T5 /* ERROR "invalid recursive type" */ [unsafe.Sizeof(*f5())]int
42
43 // Below is additional syntax which interacts with incomplete types. Notice that
44 // each of the below falls into 1 of 3 cases:
45 // 1. It cannot produce a value of (incomplete) type T.
46 // 2. It can, but only because it already has a value of type T.
47 // 3. It can, but only because it performs an implicit dereference.
48
49 // select on type (case 1)
50 // select on value (case 2)
51 type T6 /* ERROR "invalid recursive type" */ struct {
52 f T7
53 }
54 type T7 [unsafe.Sizeof(T6{}.f)]int
55 // select on pointer (case 3)
56 type T8 /* ERROR "invalid recursive type" */ struct {
57 f T9
58 }
59 type T9 [unsafe.Sizeof(new(T8).f)]int
60
61 // slice on type (not applicable)
62 // slice on value (case 2)
63 type T10 /* ERROR "invalid recursive type" */ [unsafe.Sizeof(T10{}[:])]int
64 // slice on pointer (case 3)
65 type T11 /* ERROR "invalid recursive type" */ [unsafe.Sizeof(new(T11)[:])]int
66
67 // index on type (case 1)
68 // index on value (case 2)
69 type T12 /* ERROR "invalid recursive type" */ [unsafe.Sizeof(T12{}[42])]int
70 // index on pointer (case 3)
71 type T13 /* ERROR "invalid recursive type" */ [unsafe.Sizeof(new(T13)[42])]int