1 // $G $D/$F.go && $L $F.$A && ./$A.out
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.
12 func use(b bool) { global = b }
14 func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) }
16 func isfalse(b bool) {
18 // stack will explain where
19 panic("wanted false, got true")
25 // stack will explain where
26 panic("wanted true, got false")
36 var c string = "hello"
37 var d string = "hel" // try to get different pointer
39 if stringptr(c) == stringptr(d) {
40 panic("compiler too smart -- got same string")
43 var e = make(chan int)
45 var ia interface{} = a
46 var ib interface{} = b
47 var ic interface{} = c
48 var id interface{} = d
49 var ie interface{} = e
51 // these comparisons are okay because
52 // string compare is okay and the others
53 // are comparisons where the types differ.
70 // these are not okay, because there is no comparison on slices or maps.
104 // 6g used to let this go through as true.
107 var ig interface{} = g
108 var ih interface{} = h
112 // map of interface should use == on interface values,
114 var m = make(map[interface{}]int)
118 println("m[c] = ", m[c])
122 // non-interface comparisons
125 c1 := (<-chan int)(c)
126 c2 := (chan<- int)(c)
153 // named types vs not
205 var m = make(map[struct {
221 var m1 = make(map[struct {
240 var ix, iy, iz interface{} = x, y, z
287 var x = [2]string{"1", "hi"}
288 var y = [2]string{"2", "bye"}
289 var z = [2]string{"1", "hi"}
305 var m = make(map[[2]string]int)
316 var ix, iy, iz interface{} = x, y, z
369 var ia interface{} = a
375 var ib interface{} = b
381 var ia interface{} = a
382 var m = make(map[interface{}]int)
388 var ib interface{} = b
389 var m = make(map[interface{}]int)
393 func shouldPanic(f func()) {
395 if recover() == nil {
396 panic("function should panic")