reflect: canonicalize types returned by StructOf() and friends
[official-gcc.git] / gcc / testsuite / go.test / test / func5.go
blob2e058be7e6e19526fb24502964b5466d6e3fa86a
1 // run
3 // Copyright 2009 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 functions and goroutines.
9 package main
11 func caller(f func(int, int) int, a, b int, c chan int) {
12 c <- f(a, b)
15 func gocall(f func(int, int) int, a, b int) int {
16 c := make(chan int)
17 go caller(f, a, b, c)
18 return <-c
21 func call(f func(int, int) int, a, b int) int {
22 return f(a, b)
25 func call1(f func(int, int) int, a, b int) int {
26 return call(f, a, b)
29 var f func(int, int) int
31 func add(x, y int) int {
32 return x + y
35 func fn() func(int, int) int {
36 return f
39 var fc func(int, int, chan int)
41 func addc(x, y int, c chan int) {
42 c <- x+y
45 func fnc() func(int, int, chan int) {
46 return fc
49 func three(x int) {
50 if x != 3 {
51 println("wrong val", x)
52 panic("fail")
56 var notmain func()
58 func emptyresults() {}
59 func noresults() {}
61 var nothing func()
63 func main() {
64 three(call(add, 1, 2))
65 three(call1(add, 1, 2))
66 f = add
67 three(call(f, 1, 2))
68 three(call1(f, 1, 2))
69 three(call(fn(), 1, 2))
70 three(call1(fn(), 1, 2))
71 three(call(func(a, b int) int { return a + b }, 1, 2))
72 three(call1(func(a, b int) int { return a + b }, 1, 2))
74 fc = addc
75 c := make(chan int)
76 go addc(1, 2, c)
77 three(<-c)
78 go fc(1, 2, c)
79 three(<-c)
80 go fnc()(1, 2, c)
81 three(<-c)
82 go func(a, b int, c chan int) { c <- a+b }(1, 2, c)
83 three(<-c)
85 emptyresults()
86 noresults()
87 nothing = emptyresults
88 nothing()
89 nothing = noresults
90 nothing()