diff options
Diffstat (limited to 'test/cmp1.go')
-rw-r--r-- | test/cmp1.go | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/test/cmp1.go b/test/cmp1.go index a119f8746..12e65bec5 100644 --- a/test/cmp1.go +++ b/test/cmp1.go @@ -8,65 +8,68 @@ package main import "unsafe" -func use(bool) { } +func use(bool) {} -func stringptr(s string) uintptr { - return *(*uintptr)(unsafe.Pointer(&s)); -} +func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) } func isfalse(b bool) { - if b { panicln("wanted false, got true") } // stack will explain where + if b { + // stack will explain where + panic("wanted false, got true") + } } func istrue(b bool) { - if !b { panicln("wanted true, got false") } // stack will explain where + if !b { + // stack will explain where + panic("wanted true, got false") + } } func main() { - var a []int; - var b map[string]int; + var a []int + var b map[string]int - var c string = "hello"; - var d string = "hel"; // try to get different pointer - d = d + "lo"; + var c string = "hello" + var d string = "hel" // try to get different pointer + d = d + "lo" if stringptr(c) == stringptr(d) { panic("compiler too smart -- got same string") } - var e = make(chan int); + var e = make(chan int) + + var ia interface{} = a + var ib interface{} = b + var ic interface{} = c + var id interface{} = d + var ie interface{} = e - var ia interface{} = a; - var ib interface{} = b; - var ic interface{} = c; - var id interface{} = d; - var ie interface{} = e; - // these comparisons are okay because // string compare is okay and the others // are comparisons where the types differ. - isfalse(ia == ib); - isfalse(ia == ic); - isfalse(ia == id); - isfalse(ib == ic); - isfalse(ib == id); - istrue(ic == id); - istrue(ie == ie); + isfalse(ia == ib) + isfalse(ia == ic) + isfalse(ia == id) + isfalse(ib == ic) + isfalse(ib == id) + istrue(ic == id) + istrue(ie == ie) // 6g used to let this go through as true. - var g uint64 = 123; - var h int64 = 123; - var ig interface{} = g; - var ih interface{} = h; - isfalse(ig == ih); + var g uint64 = 123 + var h int64 = 123 + var ig interface{} = g + var ih interface{} = h + isfalse(ig == ih) // map of interface should use == on interface values, // not memory. // TODO: should m[c], m[d] be valid here? - var m = make(map[interface{}] int); - m[ic] = 1; - m[id] = 2; + var m = make(map[interface{}]int) + m[ic] = 1 + m[id] = 2 if m[ic] != 2 { - panic("m[ic] = ", m[ic]); + panic("m[ic] = ", m[ic]) } } - |