]> Cypherpunks.ru repositories - gostls13.git/blobdiff - test/cmp.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / cmp.go
index a56ca6eadddc2732dbf3245a51980c3f4e33e9a3..6db9ce5cc85b8b6223e88479301853bbe3cd009a 100644 (file)
@@ -8,9 +8,13 @@
 
 package main
 
-import "unsafe"
+import (
+       "os"
+       "unsafe"
+)
 
 var global bool
+
 func use(b bool) { global = b }
 
 func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) }
@@ -31,6 +35,10 @@ func istrue(b bool) {
 
 type T *int
 
+type X int
+
+func (X) x() {}
+
 func main() {
        var a []int
        var b map[string]int
@@ -38,8 +46,12 @@ func main() {
        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")
+
+       // go.tools/ssa/interp can't handle unsafe.Pointer.
+       if os.Getenv("GOSSAINTERP") == "" {
+               if stringptr(c) == stringptr(d) {
+                       panic("compiler too smart -- got same string")
+               }
        }
 
        var e = make(chan int)
@@ -103,7 +115,7 @@ func main() {
        isfalse(ic != d)
        isfalse(ie != e)
 
-       // 6g used to let this go through as true.
+       // gc used to let this go through as true.
        var g uint64 = 123
        var h int64 = 123
        var ig interface{} = g
@@ -121,6 +133,44 @@ func main() {
                panic("bad m[c]")
        }
 
+       // interface comparisons (issue 7207)
+       {
+               type I1 interface {
+                       x()
+               }
+               type I2 interface {
+                       x()
+               }
+               a1 := I1(X(0))
+               b1 := I1(X(1))
+               a2 := I2(X(0))
+               b2 := I2(X(1))
+               a3 := I1(a2)
+               a4 := I2(a1)
+               var e interface{} = X(0)
+               a5 := e.(I1)
+               a6 := e.(I2)
+               isfalse(a1 == b1)
+               isfalse(a1 == b2)
+               isfalse(a2 == b1)
+               isfalse(a2 == b2)
+               istrue(a1 == a2)
+               istrue(a1 == a3)
+               istrue(a1 == a4)
+               istrue(a1 == a5)
+               istrue(a1 == a6)
+               istrue(a2 == a3)
+               istrue(a2 == a4)
+               istrue(a2 == a5)
+               istrue(a2 == a6)
+               istrue(a3 == a4)
+               istrue(a3 == a5)
+               istrue(a3 == a6)
+               istrue(a4 == a5)
+               istrue(a4 == a6)
+               istrue(a5 == a6)
+       }
+
        // non-interface comparisons
        {
                c := make(chan int)
@@ -283,12 +333,12 @@ func main() {
                isfalse(ix != z)
                isfalse(iz != x)
        }
-       
+
        // structs with _ fields
        {
                var x = struct {
                        x int
-                       _ []int
+                       _ string
                        y float64
                        _ float64
                        z int
@@ -296,7 +346,7 @@ func main() {
                        x: 1, y: 2, z: 3,
                }
                var ix interface{} = x
-               
+
                istrue(x == x)
                istrue(x == ix)
                istrue(ix == x)
@@ -379,6 +429,23 @@ func main() {
                isfalse(iz != x)
        }
 
+       // named booleans
+       {
+               type mybool bool
+               var b mybool
+
+               type T struct{ data [20]byte }
+               var x, y T
+               b = x == y
+               istrue(x == y)
+               istrue(bool(b))
+
+               m := make(map[string][10]interface{})
+               b = m["x"] == m["y"]
+               istrue(m["x"] == m["y"])
+               istrue(bool(b))
+       }
+
        shouldPanic(p1)
        shouldPanic(p2)
        shouldPanic(p3)