Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / libgo / go / go / types / testdata / decls0.src
1 // Copyright 2011 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 // type declarations
6
7 package decls0
8
9 import (
10         "unsafe"
11         // we can have multiple blank imports (was bug)
12         _ "math"
13         _ "net/rpc"
14 )
15
16 const pi = 3.1415
17
18 type (
19         N undeclared /* ERROR "undeclared" */
20         B bool
21         I int32
22         A [10]P
23         T struct {
24                 x, y P
25         }
26         P *T
27         R (*R)
28         F func(A) I
29         Y interface {
30                 f(A) I
31         }
32         S [](((P)))
33         M map[I]F
34         C chan<- I
35
36         // blank types must be typechecked
37         _ pi /* ERROR "not a type" */
38         _ struct{}
39         _ struct{ pi /* ERROR "not a type" */ }
40 )
41
42
43 // invalid array types
44 type (
45         iA0 [... /* ERROR "invalid use of '...'" */ ]byte
46         iA1 [1 /* ERROR "invalid array length" */ <<100]int
47         iA2 [- /* ERROR "invalid array length" */ 1]complex128
48         iA3 ["foo" /* ERROR "invalid array length" */ ]string
49 )
50
51
52 type (
53         p1 pi /* ERROR "no single field or method foo" */ .foo
54         p2 unsafe.Pointer
55 )
56
57
58 type (
59         Pi pi /* ERROR "not a type" */
60
61         a /* ERROR "illegal cycle" */ a
62         a /* ERROR "redeclared" */ int
63
64         // where the cycle error appears depends on the
65         // order in which declarations are processed
66         // (which depends on the order in which a map
67         // is iterated through)
68         b /* ERROR "illegal cycle" */ c
69         c d
70         d e
71         e b
72
73         t *t
74
75         U V
76         V *W
77         W U
78
79         P1 *S2
80         P2 P1
81
82         S0 struct {
83         }
84         S1 struct {
85                 a, b, c int
86                 u, v, a /* ERROR "redeclared" */ float32
87         }
88         S2 struct {
89                 U // anonymous field
90                 // TODO(gri) recognize double-declaration below
91                 // U /* ERROR "redeclared" */ int
92         }
93         S3 struct {
94                 x S2
95         }
96         S4/* ERROR "illegal cycle" */ struct {
97                 S4
98         }
99         S5 /* ERROR "illegal cycle" */ struct {
100                 S6
101         }
102         S6 struct {
103                 field S7
104         }
105         S7 struct {
106                 S5
107         }
108
109         L1 []L1
110         L2 []int
111
112         A1 [10.0]int
113         A2 /* ERROR "illegal cycle" */ [10]A2
114         A3 /* ERROR "illegal cycle" */ [10]struct {
115                 x A4
116         }
117         A4 [10]A3
118
119         F1 func()
120         F2 func(x, y, z float32)
121         F3 func(x, y, x /* ERROR "redeclared" */ float32)
122         F4 func() (x, y, x /* ERROR "redeclared" */ float32)
123         F5 func(x int) (x /* ERROR "redeclared" */ float32)
124         F6 func(x ...int)
125
126         I1 interface{}
127         I2 interface {
128                 m1()
129         }
130         I3 interface { /* ERROR "multiple methods named m1" */
131                 m1()
132                 m1 /* ERROR "redeclared" */ ()
133         }
134         I4 interface {
135                 m1(x, y, x /* ERROR "redeclared" */ float32)
136                 m2() (x, y, x /* ERROR "redeclared" */ float32)
137                 m3(x int) (x /* ERROR "redeclared" */ float32)
138         }
139         I5 interface {
140                 m1(I5)
141         }
142         I6 interface {
143                 S0 /* ERROR "not an interface" */
144         }
145         I7 interface {
146                 I1
147                 I1
148         }
149         I8 /* ERROR "illegal cycle" */ interface {
150                 I8
151         }
152         // Use I09 (rather than I9) because it appears lexically before
153         // I10 so that we get the illegal cycle here rather then in the
154         // declaration of I10. If the implementation sorts by position
155         // rather than name, the error message will still be here.
156         I09 /* ERROR "illegal cycle" */ interface {
157                 I10
158         }
159         I10 interface {
160                 I11
161         }
162         I11 interface {
163                 I09
164         }
165
166         C1 chan int
167         C2 <-chan int
168         C3 chan<- C3
169         C4 chan C5
170         C5 chan C6
171         C6 chan C4
172
173         M1 map[Last]string
174         M2 map[string]M2
175
176         Last int
177 )