| 1 |
// compile |
| 2 |
|
| 3 |
// Copyright 2010 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
// Test cases for conversion syntax. |
| 8 |
|
| 9 |
package main |
| 10 |
|
| 11 |
type ( |
| 12 |
A [3]int |
| 13 |
S struct { |
| 14 |
x int |
| 15 |
} |
| 16 |
P *S |
| 17 |
F func(x int) int |
| 18 |
I interface { |
| 19 |
m(x int) int |
| 20 |
} |
| 21 |
L []int |
| 22 |
M map[string]int |
| 23 |
C chan int |
| 24 |
) |
| 25 |
|
| 26 |
func (s S) m(x int) int { return x } |
| 27 |
|
| 28 |
var ( |
| 29 |
a A = [...]int{1, 2, 3} |
| 30 |
s S = struct{ x int }{0} |
| 31 |
p P = &s |
| 32 |
f F = func(x int) int { return x } |
| 33 |
i I = s |
| 34 |
l L = []int{} |
| 35 |
m M = map[string]int{"foo": 0} |
| 36 |
c C = make(chan int) |
| 37 |
) |
| 38 |
|
| 39 |
func main() { |
| 40 |
a = A(a) |
| 41 |
a = [3]int(a) |
| 42 |
s = struct { |
| 43 |
x int |
| 44 |
}(s) |
| 45 |
p = (*S)(p) |
| 46 |
f = func(x int) int(f) |
| 47 |
i = (interface { |
| 48 |
m(x int) int |
| 49 |
})(s) // this is accepted by 6g |
| 50 |
i = interface { |
| 51 |
m(x int) int |
| 52 |
}(s) // this is not accepted by 6g (but should be) |
| 53 |
l = []int(l) |
| 54 |
m = map[string]int(m) |
| 55 |
c = chan int(c) |
| 56 |
_ = chan<- int(c) |
| 57 |
_ = <-(chan int)(c) |
| 58 |
_ = <-(<-chan int)(c) |
| 59 |
} |
| 60 |
|
| 61 |
/* |
| 62 |
6g bug277.go |
| 63 |
bug277.go:46: syntax error: unexpected (, expecting { |
| 64 |
bug277.go:50: syntax error: unexpected interface |
| 65 |
bug277.go:53: non-declaration statement outside function body |
| 66 |
bug277.go:54: non-declaration statement outside function body |
| 67 |
bug277.go:55: syntax error: unexpected LCHAN |
| 68 |
bug277.go:56: syntax error: unexpected LCHAN |
| 69 |
bug277.go:57: non-declaration statement outside function body |
| 70 |
bug277.go:58: non-declaration statement outside function body |
| 71 |
bug277.go:59: syntax error: unexpected } |
| 72 |
*/ |