Reverting merge from trunk
[official-gcc.git] / gcc / testsuite / go.test / test / blank.go
blob7f7d9f6f7fbac6a7c6ad3eec1eb5df661229d82c
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 behavior of the blank identifier (_).
9 package main
11 import (
12 "os"
13 "unsafe"
16 import _ "fmt"
18 var call string
20 type T struct {
21 _, _, _ int
24 func (T) _() {
27 func (T) _() {
30 const (
31 c0 = iota
38 var ints = []string{
39 "1",
40 "2",
41 "3",
44 func f() (int, int) {
45 call += "f"
46 return 1, 2
49 func g() (float64, float64) {
50 call += "g"
51 return 3, 4
54 func h(_ int, _ float64) {
57 func i() int {
58 call += "i"
59 return 23
62 var _ = i()
64 func main() {
65 if call != "i" {
66 panic("init did not run")
68 call = ""
69 _, _ = f()
70 a, _ := f()
71 if a != 1 {
72 panic(a)
74 b, _ := g()
75 if b != 3 {
76 panic(b)
78 _, a = f()
79 if a != 2 {
80 panic(a)
82 _, b = g()
83 if b != 4 {
84 panic(b)
86 _ = i()
87 if call != "ffgfgi" {
88 panic(call)
90 if c4 != 4 {
91 panic(c4)
94 out := ""
95 for _, s := range ints {
96 out += s
98 if out != "123" {
99 panic(out)
102 sum := 0
103 for s := range ints {
104 sum += s
106 if sum != 3 {
107 panic(sum)
110 // exp/ssa/interp doesn't yet skip blank fields in struct
111 // equivalence. It also cannot support unsafe.Pointer.
112 if os.Getenv("GOSSAINTERP") == "" {
113 type T1 struct{ x, y, z int }
114 t1 := *(*T)(unsafe.Pointer(&T1{1, 2, 3}))
115 t2 := *(*T)(unsafe.Pointer(&T1{4, 5, 6}))
116 if t1 != t2 {
117 panic("T{} != T{}")
121 h(a, b)
126 type I interface {
127 M(_ int, y int)
130 type TI struct{}
132 func (_ TI) M(x int, y int) {
133 if x != y {
134 println("invalid M call:", x, y)
135 panic("bad M")
139 var fp = func(_ int, y int) {}
141 func init() {
142 fp = fp1
145 func fp1(x, y int) {
146 if x != y {
147 println("invalid fp1 call:", x, y)
148 panic("bad fp1")
152 func m() {
153 var i I
155 i = TI{}
156 i.M(1, 1)
157 i.M(2, 2)
159 fp(1, 1)
160 fp(2, 2)
163 // useless but legal
164 var _ int = 1
165 var _ = 2
166 var _, _ = 3, 4
168 const _ = 3
169 const _, _ = 4, 5
171 type _ int
173 func _() {
174 panic("oops")
177 func ff() {
178 var _ int = 1