github.com/yanyiwu/go@v0.0.0-20150106053140-03d6637dbb7f/test/interface/embed2.go (about)

     1  // errorcheck
     2  
     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.
     6  
     7  // Test methods derived from embedded interface and *interface values.
     8  
     9  package main
    10  
    11  import "os"
    12  
    13  const Value = 1e12
    14  
    15  type Inter interface { M() int64 }
    16  
    17  type T int64
    18  func (t T) M() int64 { return int64(t) }
    19  var t = T(Value)
    20  var pt = &t
    21  var ti Inter = t
    22  var pti = &ti
    23  
    24  type S struct { Inter }
    25  var s = S{ ti }
    26  var ps = &s
    27  
    28  type SP struct { *Inter }	// ERROR "interface"
    29  
    30  var i Inter
    31  var pi = &i
    32  
    33  var ok = true
    34  
    35  func check(s string, v int64) {
    36  	if v != Value {
    37  		println(s, v)
    38  		ok = false
    39  	}
    40  }
    41  
    42  func main() {
    43  	check("t.M()", t.M())
    44  	check("pt.M()", pt.M())
    45  	check("ti.M()", ti.M())
    46  	check("pti.M()", pti.M())	// ERROR "method"
    47  	check("s.M()", s.M())
    48  	check("ps.M()", ps.M())
    49  
    50  	i = t
    51  	check("i = t; i.M()", i.M())
    52  	check("i = t; pi.M()", pi.M())	// ERROR "method"
    53  
    54  	i = pt
    55  	check("i = pt; i.M()", i.M())
    56  	check("i = pt; pi.M()", pi.M())	// ERROR "method"
    57  
    58  	i = s
    59  	check("i = s; i.M()", i.M())
    60  	check("i = s; pi.M()", pi.M())	// ERROR "method"
    61  
    62  	i = ps
    63  	check("i = ps; i.M()", i.M())
    64  	check("i = ps; pi.M()", pi.M())	// ERROR "method"
    65  
    66  	if !ok {
    67  		println("BUG: interface10")
    68  		os.Exit(1)
    69  	}
    70  }