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