2009-05-07 14:43:00 -06:00
|
|
|
// $G $D/$F.go && $L $F.$A && ./$A.out
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2010-09-30 12:59:41 -06:00
|
|
|
// Check methods derived from embedded interface values.
|
2009-05-12 17:09:47 -06:00
|
|
|
|
2009-05-07 14:43:00 -06:00
|
|
|
package main
|
|
|
|
|
2009-05-08 16:21:41 -06:00
|
|
|
import "os"
|
|
|
|
|
2009-05-07 14:43:00 -06:00
|
|
|
const Value = 1e12
|
|
|
|
|
|
|
|
type Inter interface { M() int64 }
|
|
|
|
|
|
|
|
type T int64
|
2009-05-08 16:40:14 -06:00
|
|
|
func (t T) M() int64 { return int64(t) }
|
2009-05-07 14:43:00 -06:00
|
|
|
var t = T(Value)
|
|
|
|
var pt = &t
|
|
|
|
var ti Inter = t
|
|
|
|
|
|
|
|
type S struct { Inter }
|
|
|
|
var s = S{ ti }
|
|
|
|
var ps = &s
|
|
|
|
|
|
|
|
var i Inter
|
|
|
|
|
|
|
|
var ok = true
|
|
|
|
|
2009-10-19 20:27:40 -06:00
|
|
|
func check(s string, v int64) {
|
2009-05-07 14:43:00 -06:00
|
|
|
if v != Value {
|
2010-09-03 18:36:13 -06:00
|
|
|
println(s, v)
|
|
|
|
ok = false
|
2009-05-07 14:43:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2010-09-03 18:36:13 -06:00
|
|
|
check("t.M()", t.M())
|
|
|
|
check("pt.M()", pt.M())
|
|
|
|
check("ti.M()", ti.M())
|
|
|
|
check("s.M()", s.M())
|
|
|
|
check("ps.M()", ps.M())
|
|
|
|
|
|
|
|
i = t
|
|
|
|
check("i = t; i.M()", i.M())
|
|
|
|
|
|
|
|
i = pt
|
|
|
|
check("i = pt; i.M()", i.M())
|
|
|
|
|
|
|
|
i = s
|
|
|
|
check("i = s; i.M()", i.M())
|
|
|
|
|
|
|
|
i = ps
|
|
|
|
check("i = ps; i.M()", i.M())
|
2009-05-07 14:43:00 -06:00
|
|
|
|
|
|
|
if !ok {
|
2010-09-03 18:36:13 -06:00
|
|
|
println("BUG: interface10")
|
2009-05-08 16:21:41 -06:00
|
|
|
os.Exit(1)
|
2009-05-07 14:43:00 -06:00
|
|
|
}
|
|
|
|
}
|