aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/libgo/go/go/types/testdata/stmt0.src
blob: ca36834fde6d508368b5c75052a3907c9487a01d (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
// Copyright 2012 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.

// statements

package stmt0

func _() {
	b, i, f, c, s := false, 1, 1.0, 1i, "foo"
	b = i /* ERROR "cannot assign" */
	i = f /* ERROR "cannot assign" */
	f = c /* ERROR "cannot assign" */
	c = s /* ERROR "cannot assign" */
	s = b /* ERROR "cannot assign" */

	v0 /* ERROR "mismatch" */, v1, v2 := 1, 2, 3, 4

	b = true

	i += 1
	i += "foo" /* ERROR "cannot convert.*int" */

	f -= 1
	f -= "foo" /* ERROR "cannot convert.*float64" */

	c *= 1
	c /= 0 /* ERROR "division by zero" */

	s += "bar"
	s += 1 /* ERROR "cannot convert.*string" */
}

func _incdecs() {
	const c = 3.14
	c /* ERROR "cannot assign" */ ++
	s := "foo"
	s /* ERROR "cannot convert" */ --
	3.14 /* ERROR "cannot assign" */ ++
	var (
		x int
		y float32
		z complex128
	)
	x++
	y--
	z++
}

func _sends() {
	var ch chan int
	var rch <-chan int
	var x int
	x /* ERROR "cannot send" */ <- x
	rch /* ERROR "cannot send" */ <- x
	ch /* ERROR "cannot send" */ <- "foo"
	ch <- x
}

func _selects() {
	select {}
	var (
		ch chan int
		sc chan <- bool
		x int
	)
	select {
	case <-ch:
		ch <- x
	case t, ok := <-ch:
		x = t
	case <-sc /* ERROR "cannot receive from send-only channel" */ :
	}
	select {
	default:
	default /* ERROR "multiple defaults" */ :
	}
}

func _gos() {
	go 1 /* ERROR "expected function/method call" */
	go _gos()
	var c chan int
	go close(c)
	go len(c) // TODO(gri) this should not be legal
}

func _defers() {
	defer 1 /* ERROR "expected function/method call" */
	defer _defers()
	var c chan int
	defer close(c)
	defer len(c) // TODO(gri) this should not be legal
}

func _switches() {
	var x int

	switch x {
	default:
	default /* ERROR "multiple defaults" */ :
	}

	switch {
	case 1  /* ERROR "cannot convert" */ :
	}

	switch int32(x) {
	case 1, 2:
	case x /* ERROR "cannot compare" */ :
	}

	switch x {
	case 1 /* ERROR "overflows int" */ << 100:
	}

	switch x {
	case 1:
	case 1 /* ERROR "duplicate case" */ :
	case 2, 3, 4:
	case 1 /* ERROR "duplicate case" */ :
	}

	// TODO(gri) duplicate 64bit values that don't fit into an int64 are not yet detected
	switch uint64(x) {
	case 1<<64-1:
	case 1<<64-1:
	}
}

type I interface {
	m()
}

type I2 interface {
	m(int)
}

type T struct{}
type T1 struct{}
type T2 struct{}

func (T) m() {}
func (T2) m(int) {}

func _typeswitches() {
	var i int
	var x interface{}

	switch x.(type) {}
	switch (x /* ERROR "outside type switch" */ .(type)) {}

	switch x.(type) {
	default:
	default /* ERROR "multiple defaults" */ :
	}

	switch x := x.(type) {}

	switch x := x.(type) {
	case int:
		var y int = x
	}

	switch x := i /* ERROR "not an interface" */ .(type) {}

	switch t := x.(type) {
	case nil:
		var v bool = t /* ERROR "cannot assign" */
	case int:
		var v int = t
	case float32, complex64:
		var v float32 = t /* ERROR "cannot assign" */
	default:
		var v float32 = t /* ERROR "cannot assign" */
	}

	var t I
	switch t.(type) {
	case T:
	case T1 /* ERROR "missing method m" */ :
	case T2 /* ERROR "wrong type for method m" */ :
	case I2 /* ERROR "wrong type for method m" */ :
	}
}

func _rangeloops() {
	var (
		x int
		a [10]float32
		b []string
		p *[10]complex128
		pp **[10]complex128
		s string
		m map[int]bool
		c chan int
		sc chan<- int
		rc <-chan int
	)

	for _ = range x /* ERROR "cannot range over" */ {}
	for i := range x /* ERROR "cannot range over" */ {}

	for i := range a {
		var ii int
		ii = i
	}
	for i, x := range a {
		var ii int
		ii = i
		var xx float64
		xx = x /* ERROR "cannot assign" */
	}
	var ii int
	var xx float32
	for ii, xx := range a {}

	for i := range b {
		var ii int
		ii = i
	}
	for i, x := range b {
		var ii int
		ii = i
		var xx string
		xx = x
	}

	for i := range s {
		var ii int
		ii = i
	}
	for i, x := range s {
		var ii int
		ii = i
		var xx rune
		xx = x
	}

	for _, x := range p {
		var xx complex128
		xx = x
	}

	for _, x := range pp /* ERROR "cannot range over" */ {}

	for k := range m {
		var kk int32
		kk = k /* ERROR "cannot assign" */
	}
	for k, v := range m {
		var kk int
		kk = k
		if v {}
	}

	for _, _ /* ERROR "only one iteration variable" */ = range c {}
	for e := range c {
		var ee int
		ee = e
	}
	for _ = range sc /* ERROR "cannot range over send-only channel" */ {}
	for _ = range rc {}

	// constant strings
	const cs = "foo"
	for i, x := range cs {}
	for i, x := range "" {
		var ii int
		ii = i
		var xx rune
		xx = x
	}
}