Merge from trunk
[official-gcc.git] / gcc / testsuite / go.test / test / const4.go
blob2fb2d0664e8525383382258ad1f24654eb243bdd
1 // run
3 // Copyright 2011 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.
7 // Test len constants and non-constants, http://golang.org/issue/3244.
9 package main
11 var b struct {
12 a [10]int
15 var m map[string][20]int
17 var s [][30]int
19 const (
20 n1 = len(b.a)
21 n2 = len(m[""])
22 n3 = len(s[10])
25 // Non-constants (see also const5.go).
26 var (
27 n4 = len(f())
28 n5 = len(<-c)
29 n6 = cap(g())
30 n7 = cap(<-c1)
33 var calledF = false
35 func f() *[40]int {
36 calledF = true
37 return nil
40 var c = func() chan *[50]int {
41 c := make(chan *[50]int, 2)
42 c <- nil
43 c <- new([50]int)
44 return c
45 }()
47 var calledG = false
49 func g() *[60]int {
50 calledG = true
51 return nil
54 var c1 = func() chan *[70]int {
55 c := make(chan *[70]int, 2)
56 c <- nil
57 c <- new([70]int)
58 return c
59 }()
61 func main() {
62 if n1 != 10 || n2 != 20 || n3 != 30 || n4 != 40 || n5 != 50 || n6 != 60 || n7 != 70 {
63 println("BUG:", n1, n2, n3, n4, n5, n6, n7)
64 panic("fail")
66 if !calledF {
67 println("BUG: did not call f")
68 panic("fail")
70 if <-c == nil {
71 println("BUG: did not receive from c")
72 panic("fail")
74 if !calledG {
75 println("BUG: did not call g")
76 panic("fail")
78 if <-c1 == nil {
79 println("BUG: did not receive from c1")
80 panic("fail")