Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 1 | // $G $D/$F.go && $L $F.$A && ./$A.out |
| 2 | |
| 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. |
| 6 | |
| 7 | package main |
| 8 | |
Russ Cox | aa6e81dd | 2009-09-09 16:59:41 -0700 | [diff] [blame] | 9 | import _ "fmt" |
| 10 | |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 11 | var call string |
| 12 | |
| 13 | type T struct { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 14 | _, _, _ int |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 15 | } |
| 16 | |
Russ Cox | aa6e81dd | 2009-09-09 16:59:41 -0700 | [diff] [blame] | 17 | func (T) _() { |
| 18 | } |
| 19 | |
| 20 | func (T) _() { |
| 21 | } |
| 22 | |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 23 | const ( |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 24 | c0 = iota |
| 25 | _ |
| 26 | _ |
| 27 | _ |
| 28 | c4 |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 29 | ) |
| 30 | |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 31 | var ints = []string{ |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 32 | "1", |
| 33 | "2", |
Robert Griesemer | 542099d | 2009-12-09 19:27:08 -0800 | [diff] [blame] | 34 | "3", |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | func f() (int, int) { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 38 | call += "f" |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 39 | return 1, 2 |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 42 | func g() (float64, float64) { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 43 | call += "g" |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 44 | return 3, 4 |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 47 | func h(_ int, _ float64) { |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | func i() int { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 51 | call += "i" |
| 52 | return 23 |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 55 | var _ = i() |
Russ Cox | 4c3a85d | 2009-10-19 19:27:40 -0700 | [diff] [blame] | 56 | |
Russ Cox | aa6e81dd | 2009-09-09 16:59:41 -0700 | [diff] [blame] | 57 | func main() { |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 58 | if call != "i" { |
| 59 | panic("init did not run") |
| 60 | } |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 61 | call = "" |
| 62 | _, _ = f() |
| 63 | a, _ := f() |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 64 | if a != 1 { |
| 65 | panic(a) |
| 66 | } |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 67 | b, _ := g() |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 68 | if b != 3 { |
| 69 | panic(b) |
| 70 | } |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 71 | _, a = f() |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 72 | if a != 2 { |
| 73 | panic(a) |
| 74 | } |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 75 | _, b = g() |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 76 | if b != 4 { |
| 77 | panic(b) |
| 78 | } |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 79 | _ = i() |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 80 | if call != "ffgfgi" { |
| 81 | panic(call) |
| 82 | } |
| 83 | if c4 != 4 { |
| 84 | panic(c4) |
| 85 | } |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 86 | |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 87 | out := "" |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 88 | for _, s := range ints { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 89 | out += s |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 90 | } |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 91 | if out != "123" { |
| 92 | panic(out) |
| 93 | } |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 94 | |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 95 | sum := 0 |
Ryan Hitchman | 062406b | 2010-12-08 21:36:56 -0800 | [diff] [blame] | 96 | for s := range ints { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 97 | sum += s |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 98 | } |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 99 | if sum != 3 { |
| 100 | panic(sum) |
| 101 | } |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 102 | |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 103 | h(a, b) |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | // useless but legal |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 107 | var _ int = 1 |
| 108 | var _ = 2 |
| 109 | var _, _ = 3, 4 |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 110 | |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 111 | const _ = 3 |
| 112 | const _, _ = 4, 5 |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 113 | |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 114 | type _ int |
Russ Cox | f2b5a07 | 2011-01-19 23:09:00 -0500 | [diff] [blame] | 115 | |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 116 | func _() { |
| 117 | panic("oops") |
| 118 | } |
| 119 | |
| 120 | func ff() { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 121 | var _ int = 1 |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 122 | } |