]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgo/go/exp/types/staging/testdata/const0.src
libgo: Update to current sources.
[thirdparty/gcc.git] / libgo / go / exp / types / staging / testdata / const0.src
1 // Copyright 2012 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 // constant declarations
6
7 package const0
8
9 // constants declarations must be initialized by constants
10 var x = 0
11 const c0 = x /* ERROR "not constant" */
12
13 // untyped constants
14 const (
15 // boolean values
16 ub0 = false
17 ub1 = true
18 ub2 = 2 < 1
19 ub3 = ui1 == uf1
20 ub4 = true /* ERROR "cannot convert" */ == 0
21
22 // integer values
23 ui0 = 0
24 ui1 = 1
25 ui2 = 42
26 ui3 = 3141592653589793238462643383279502884197169399375105820974944592307816406286
27 ui4 = -10
28
29 ui5 = ui0 + ui1
30 ui6 = ui1 - ui1
31 ui7 = ui2 * ui1
32 ui8 = ui3 / ui3
33 ui9 = ui3 % ui3
34
35 ui10 = 1 / 0 /* ERROR "division by zero" */
36 ui11 = ui1 / 0 /* ERROR "division by zero" */
37 ui12 = ui3 / ui0 /* ERROR "division by zero" */
38 ui13 = 1 % 0 /* ERROR "division by zero" */
39 ui14 = ui1 % 0 /* ERROR "division by zero" */
40 ui15 = ui3 % ui0 /* ERROR "division by zero" */
41
42 ui16 = ui2 & ui3
43 ui17 = ui2 | ui3
44 ui18 = ui2 ^ ui3
45
46 // floating point values
47 uf0 = 0.
48 uf1 = 1.
49 uf2 = 4.2e1
50 uf3 = 3.141592653589793238462643383279502884197169399375105820974944592307816406286
51 uf4 = 1e-1
52
53 uf5 = uf0 + uf1
54 uf6 = uf1 - uf1
55 uf7 = uf2 * uf1
56 uf8 = uf3 / uf3
57 uf9 = uf3 /* ERROR "not defined" */ % uf3
58
59 uf10 = 1 / 0 /* ERROR "division by zero" */
60 uf11 = uf1 / 0 /* ERROR "division by zero" */
61 uf12 = uf3 / uf0 /* ERROR "division by zero" */
62
63 uf16 = uf2 /* ERROR "not defined" */ & uf3
64 uf17 = uf2 /* ERROR "not defined" */ | uf3
65 uf18 = uf2 /* ERROR "not defined" */ ^ uf3
66
67 // complex values
68 uc0 = 0.i
69 uc1 = 1.i
70 uc2 = 4.2e1i
71 uc3 = 3.141592653589793238462643383279502884197169399375105820974944592307816406286i
72 uc4 = 1e-1i
73
74 uc5 = uc0 + uc1
75 uc6 = uc1 - uc1
76 uc7 = uc2 * uc1
77 uc8 = uc3 / uc3
78 uc9 = uc3 /* ERROR "not defined" */ % uc3
79
80 uc10 = 1 / 0 /* ERROR "division by zero" */
81 uc11 = uc1 / 0 /* ERROR "division by zero" */
82 uc12 = uc3 / uc0 /* ERROR "division by zero" */
83
84 uc16 = uc2 /* ERROR "not defined" */ & uc3
85 uc17 = uc2 /* ERROR "not defined" */ | uc3
86 uc18 = uc2 /* ERROR "not defined" */ ^ uc3
87 )
88
89 type (
90 mybool bool
91 myint int
92 myfloat float64
93 mycomplex complex128
94 )
95
96 // typed constants
97 const (
98 // boolean values
99 tb0 bool = false
100 tb1 bool = true
101 tb2 mybool = 2 < 1
102 tb3 mybool = ti1 /* ERROR "cannot compare" */ == tf1
103
104 // integer values
105 ti0 int8 = ui0
106 ti1 int32 = ui1
107 ti2 int64 = ui2
108 ti3 myint = ui3 /* ERROR "overflows" */
109 ti4 myint = ui4
110
111 ti5 = ti0 /* ERROR "mismatched types" */ + ti1
112 ti6 = ti1 - ti1
113 ti7 = ti2 /* ERROR "mismatched types" */ * ti1
114 //ti8 = ti3 / ti3 // TODO(gri) enable this
115 //ti9 = ti3 % ti3 // TODO(gri) enable this
116
117 ti10 = 1 / 0 /* ERROR "division by zero" */
118 ti11 = ti1 / 0 /* ERROR "division by zero" */
119 ti12 = ti3 /* ERROR "mismatched types" */ / ti0
120 ti13 = 1 % 0 /* ERROR "division by zero" */
121 ti14 = ti1 % 0 /* ERROR "division by zero" */
122 ti15 = ti3 /* ERROR "mismatched types" */ % ti0
123
124 ti16 = ti2 /* ERROR "mismatched types" */ & ti3
125 ti17 = ti2 /* ERROR "mismatched types" */ | ti4
126 ti18 = ti2 ^ ti5 // no mismatched types error because the type of ti5 is unknown
127
128 // floating point values
129 tf0 float32 = 0.
130 tf1 float32 = 1.
131 tf2 float64 = 4.2e1
132 tf3 myfloat = 3.141592653589793238462643383279502884197169399375105820974944592307816406286
133 tf4 myfloat = 1e-1
134
135 tf5 = tf0 + tf1
136 tf6 = tf1 - tf1
137 tf7 = tf2 /* ERROR "mismatched types" */ * tf1
138 // tf8 = tf3 / tf3 // TODO(gri) enable this
139 tf9 = tf3 /* ERROR "not defined" */ % tf3
140
141 tf10 = 1 / 0 /* ERROR "division by zero" */
142 tf11 = tf1 / 0 /* ERROR "division by zero" */
143 tf12 = tf3 /* ERROR "mismatched types" */ / tf0
144
145 tf16 = tf2 /* ERROR "mismatched types" */ & tf3
146 tf17 = tf2 /* ERROR "mismatched types" */ | tf3
147 tf18 = tf2 /* ERROR "mismatched types" */ ^ tf3
148
149 // complex values
150 tc0 = 0.i
151 tc1 = 1.i
152 tc2 = 4.2e1i
153 tc3 = 3.141592653589793238462643383279502884197169399375105820974944592307816406286i
154 tc4 = 1e-1i
155
156 tc5 = tc0 + tc1
157 tc6 = tc1 - tc1
158 tc7 = tc2 * tc1
159 tc8 = tc3 / tc3
160 tc9 = tc3 /* ERROR "not defined" */ % tc3
161
162 tc10 = 1 / 0 /* ERROR "division by zero" */
163 tc11 = tc1 / 0 /* ERROR "division by zero" */
164 tc12 = tc3 / tc0 /* ERROR "division by zero" */
165
166 tc16 = tc2 /* ERROR "not defined" */ & tc3
167 tc17 = tc2 /* ERROR "not defined" */ | tc3
168 tc18 = tc2 /* ERROR "not defined" */ ^ tc3
169 )
170
171 // initialization cycles
172 const (
173 a /* ERROR "cycle" */ = a
174 b /* ERROR "cycle" */ , c /* ERROR "cycle" */, d, e = e, d, c, b // TODO(gri) should only have one cycle error
175 f float64 = d
176 )
177
178 // multiple initialization
179 const (
180 a1, a2, a3 = 7, 3.1415926, "foo"
181 b1, b2, b3 = b3, b1, 42
182 _p0 = assert(a1 == 7)
183 _p1 = assert(a2 == 3.1415926)
184 _p2 = assert(a3 == "foo")
185 _p3 = assert(b1 == 42)
186 _p4 = assert(b2 == 42)
187 _p5 = assert(b3 == 42)
188 )
189
190 // iota
191 const (
192 iota0 = iota
193 iota1 = iota
194 iota2 = iota*2
195 _a0 = assert(iota0 == 0)
196 _a1 = assert(iota1 == 1)
197 _a2 = assert(iota2 == 4)
198 iota6 = iota*3
199
200 iota7
201 iota8
202 _a3 = assert(iota7 == 21)
203 _a4 = assert(iota8 == 24)
204 )
205
206 const (
207 _b0 = iota
208 _b1 = assert(iota + iota2 == 5)
209 )