]> Cypherpunks.ru repositories - gostls13.git/blobdiff - test/blank.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / blank.go
index 681a5e77cb47fc74fb6798b040c006e5bf1bcc6a..0539debb1f25249788954bf0704db109ae1d635b 100644 (file)
@@ -1,11 +1,18 @@
-// $G $D/$F.go && $L $F.$A && ./$A.out
+// run
 
 // Copyright 2009 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// Test behavior of the blank identifier (_).
+
 package main
 
+import (
+       "os"
+       "unsafe"
+)
+
 import _ "fmt"
 
 var call string
@@ -20,6 +27,10 @@ func (T) _() {
 func (T) _() {
 }
 
+type U struct {
+       _ struct{ a, b, c int }
+}
+
 const (
        c0 = iota
        _
@@ -100,7 +111,63 @@ func main() {
                panic(sum)
        }
 
+       // go.tools/ssa/interp cannot support unsafe.Pointer.
+       if os.Getenv("GOSSAINTERP") == "" {
+               type T1 struct{ x, y, z int }
+               t1 := *(*T)(unsafe.Pointer(&T1{1, 2, 3}))
+               t2 := *(*T)(unsafe.Pointer(&T1{4, 5, 6}))
+               if t1 != t2 {
+                       panic("T{} != T{}")
+               }
+
+               var u1, u2 interface{}
+               u1 = *(*U)(unsafe.Pointer(&T1{1, 2, 3}))
+               u2 = *(*U)(unsafe.Pointer(&T1{4, 5, 6}))
+               if u1 != u2 {
+                       panic("U{} != U{}")
+               }
+       }
+
        h(a, b)
+
+       m()
+}
+
+type I interface {
+       M(_ int, y int)
+}
+
+type TI struct{}
+
+func (_ TI) M(x int, y int) {
+       if x != y {
+               println("invalid M call:", x, y)
+               panic("bad M")
+       }
+}
+
+var fp = func(_ int, y int) {}
+
+func init() {
+       fp = fp1
+}
+
+func fp1(x, y int) {
+       if x != y {
+               println("invalid fp1 call:", x, y)
+               panic("bad fp1")
+       }
+}
+
+func m() {
+       var i I
+
+       i = TI{}
+       i.M(1, 1)
+       i.M(2, 2)
+
+       fp(1, 1)
+       fp(2, 2)
 }
 
 // useless but legal