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.
5 // constant declarations
9 // constants declarations must be initialized by constants
11 const c0 = x /* ERROR "not constant" */
20 ub4 = true /* ERROR "cannot convert" */ == 0
26 ui3 = 3141592653589793238462643383279502884197169399375105820974944592307816406286
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" */
46 // floating point values
50 uf3 = 3.141592653589793238462643383279502884197169399375105820974944592307816406286
57 uf9 = uf3 /* ERROR "not defined" */ % uf3
59 uf10 = 1 / 0 /* ERROR "division by zero" */
60 uf11 = uf1 / 0 /* ERROR "division by zero" */
61 uf12 = uf3 / uf0 /* ERROR "division by zero" */
63 uf16 = uf2 /* ERROR "not defined" */ & uf3
64 uf17 = uf2 /* ERROR "not defined" */ | uf3
65 uf18 = uf2 /* ERROR "not defined" */ ^ uf3
71 uc3 = 3.141592653589793238462643383279502884197169399375105820974944592307816406286i
78 uc9 = uc3 /* ERROR "not defined" */ % uc3
80 uc10 = 1 / 0 /* ERROR "division by zero" */
81 uc11 = uc1 / 0 /* ERROR "division by zero" */
82 uc12 = uc3 / uc0 /* ERROR "division by zero" */
84 uc16 = uc2 /* ERROR "not defined" */ & uc3
85 uc17 = uc2 /* ERROR "not defined" */ | uc3
86 uc18 = uc2 /* ERROR "not defined" */ ^ uc3
102 tb3 mybool = ti1 /* ERROR "cannot compare" */ == tf1
108 ti3 myint = ui3 /* ERROR "overflows" */
111 ti5 = ti0 /* ERROR "mismatched types" */ + ti1
113 ti7 = ti2 /* ERROR "mismatched types" */ * ti1
114 //ti8 = ti3 / ti3 // TODO(gri) enable this
115 //ti9 = ti3 % ti3 // TODO(gri) enable this
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
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
128 // floating point values
132 tf3 myfloat = 3.141592653589793238462643383279502884197169399375105820974944592307816406286
137 tf7 = tf2 /* ERROR "mismatched types" */ * tf1
138 // tf8 = tf3 / tf3 // TODO(gri) enable this
139 tf9 = tf3 /* ERROR "not defined" */ % tf3
141 tf10 = 1 / 0 /* ERROR "division by zero" */
142 tf11 = tf1 / 0 /* ERROR "division by zero" */
143 tf12 = tf3 /* ERROR "mismatched types" */ / tf0
145 tf16 = tf2 /* ERROR "mismatched types" */ & tf3
146 tf17 = tf2 /* ERROR "mismatched types" */ | tf3
147 tf18 = tf2 /* ERROR "mismatched types" */ ^ tf3
153 tc3 = 3.141592653589793238462643383279502884197169399375105820974944592307816406286i
160 tc9 = tc3 /* ERROR "not defined" */ % tc3
162 tc10 = 1 / 0 /* ERROR "division by zero" */
163 tc11 = tc1 / 0 /* ERROR "division by zero" */
164 tc12 = tc3 / tc0 /* ERROR "division by zero" */
166 tc16 = tc2 /* ERROR "not defined" */ & tc3
167 tc17 = tc2 /* ERROR "not defined" */ | tc3
168 tc18 = tc2 /* ERROR "not defined" */ ^ tc3
171 // initialization cycles
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
178 // multiple initialization
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)
195 _a0 = assert(iota0 == 0)
196 _a1 = assert(iota1 == 1)
197 _a2 = assert(iota2 == 4)
202 _a3 = assert(iota7 == 21)
203 _a4 = assert(iota8 == 24)
208 _b1 = assert(iota + iota2 == 5)