blob: 5e5e2e940b3bd7e031bcc2b6dc953396288ceff2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// type aliases
package decls4
type (
T0 [10]int
T1 []byte
T2 struct {
x int
}
T3 interface{
m() T2
}
T4 func(int, T0) chan T2
)
type (
Ai = int
A0 = T0
A1 = T1
A2 = T2
A3 = T3
A4 = T4
A10 = [10]int
A11 = []byte
A12 = struct {
x int
}
A13 = interface{
m() A2
}
A14 = func(int, A0) chan A2
)
// check assignment compatibility due to equality of types
var (
xi_ int
ai Ai = xi_
x0 T0
a0 A0 = x0
x1 T1
a1 A1 = x1
x2 T2
a2 A2 = x2
x3 T3
a3 A3 = x3
x4 T4
a4 A4 = x4
)
// alias receiver types
func (Ai /* ERROR "invalid receiver" */) m1() {}
func (T0) m1() {}
func (A0) m1 /* ERROR already declared */ () {}
func (A0) m2 () {}
func (A3 /* ERROR invalid receiver */ ) m1 () {}
func (A10 /* ERROR invalid receiver */ ) m1() {}
// x0 has methods m1, m2 declared via receiver type names T0 and A0
var _ interface{ m1(); m2() } = x0
// cycles
type (
C2 /* ERROR illegal cycle */ = C2
C3 /* ERROR illegal cycle */ = C4
C4 = C3
C5 struct {
f *C6
}
C6 = C5
C7 /* ERROR illegal cycle */ struct {
f C8
}
C8 = C7
)
// embedded fields
var (
s0 struct { T0 }
s1 struct { A0 } = s0 /* ERROR cannot use */ // embedded field names are different
)
// embedding and lookup of fields and methods
func _(s struct{A0}) { s.A0 = x0 }
type eX struct{xf int}
func (eX) xm()
type eY = struct{eX} // field/method set of eY includes xf, xm
type eZ = *struct{eX} // field/method set of eZ includes xf, xm
type eA struct {
eX // eX contributes xf, xm to eA
}
type eA2 struct {
*eX // *eX contributes xf, xm to eA
}
type eB struct {
eY // eY contributes xf, xm to eB
}
type eB2 struct {
*eY // *eY contributes xf, xm to eB
}
type eC struct {
eZ // eZ contributes xf, xm to eC
}
var (
_ = eA{}.xf
_ = eA{}.xm
_ = eA2{}.xf
_ = eA2{}.xm
_ = eB{}.xf
_ = eB{}.xm
_ = eB2{}.xf
_ = eB2{}.xm
_ = eC{}.xf
_ = eC{}.xm
)
// ambiguous selectors due to embedding via type aliases
type eD struct {
eY
eZ
}
var (
_ = eD /* ERROR ambiguous selector */ {}.xf
_ = eD /* ERROR ambiguous selector */ {}.xm
)
var (
_ interface{ xm() } = eD /* ERROR missing method xm */ {}
)
|