summaryrefslogtreecommitdiffstats
path: root/test/fixedbugs/bug424.dir/main.go
blob: 28b41e68a737dfe9e3e43f0b2c99238c673ddc54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2012 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.

// Tests that method calls through an interface always
// call the locally defined method localT.m independent
// at which embedding level it is and in which order
// embedding is done.

package main

import "./lib"
import "reflect"
import "fmt"

type localI interface {
	m() string
}

type localT struct{}

func (t *localT) m() string {
	return "main.localT.m"
}

type myT1 struct {
	localT
}

type myT2 struct {
	localT
	lib.T
}

type myT3 struct {
	lib.T
	localT
}

func main() {
	var i localI

	i = new(localT)
	if i.m() != "main.localT.m" {
		println("BUG: localT:", i.m(), "called")
	}

	i = new(myT1)
	if i.m() != "main.localT.m" {
		println("BUG: myT1:", i.m(), "called")
	}

	i = new(myT2)
	if i.m() != "main.localT.m" {
		println("BUG: myT2:", i.m(), "called")
	}

	t3 := new(myT3)
	if t3.m() != "main.localT.m" {
		println("BUG: t3:", t3.m(), "called")
	}
	
	i = new(myT3)
	if i.m() != "main.localT.m" {
		t := reflect.TypeOf(i)
		n := t.NumMethod()
		for j := 0; j < n; j++ {
			m := t.Method(j)
			fmt.Printf("#%d: %s.%s %s\n", j, m.PkgPath, m.Name, m.Type)
		}
		println("BUG: myT3:", i.m(), "called")
	}
	
	var t4 struct {
		localT
		lib.T
	}
	if t4.m() != "main.localT.m" {
		println("BUG: t4:", t4.m(), "called")
	}
	i = &t4
	if i.m() != "main.localT.m" {
		println("BUG: myT4:", i.m(), "called")
	}
	
	var t5 struct {
		lib.T
		localT
	}
	if t5.m() != "main.localT.m" {
		println("BUG: t5:", t5.m(), "called")
	}
	i = &t5
	if i.m() != "main.localT.m" {
		println("BUG: myT5:", i.m(), "called")
	}
}