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.
13 func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) }
15 func isfalse(b bool) {
17 // stack will explain where
18 panic("wanted false, got true")
24 // stack will explain where
25 panic("wanted true, got false")
35 var c string = "hello"
36 var d string = "hel" // try to get different pointer
38 if stringptr(c) == stringptr(d) {
39 panic("compiler too smart -- got same string")
42 var e = make(chan int)
44 var ia interface{} = a
45 var ib interface{} = b
46 var ic interface{} = c
47 var id interface{} = d
48 var ie interface{} = e
50 // these comparisons are okay because
51 // string compare is okay and the others
52 // are comparisons where the types differ.
69 // these are not okay, because there is no comparison on slices or maps.
103 // 6g used to let this go through as true.
106 var ig interface{} = g
107 var ih interface{} = h
111 // map of interface should use == on interface values,
113 var m = make(map[interface{}]int)
117 println("m[c] = ", m[c])
121 // non-interface comparisons
124 c1 := (<-chan int)(c)
125 c2 := (chan<- int)(c)
152 // named types vs not
204 var m = make(map[struct {
220 var m1 = make(map[struct {
239 var ix, iy, iz interface{} = x, y, z
286 var x = [2]string{"1", "hi"}
287 var y = [2]string{"2", "bye"}
288 var z = [2]string{"1", "hi"}
304 var m = make(map[[2]string]int)
315 var ix, iy, iz interface{} = x, y, z
368 var ia interface{} = a
374 var ib interface{} = b
380 var ia interface{} = a
381 var m = make(map[interface{}]int)
387 var ib interface{} = b
388 var m = make(map[interface{}]int)
392 func shouldPanic(f func()) {
394 if recover() == nil {
395 panic("function should panic")