diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 13:14:23 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 13:14:23 +0000 |
commit | 73df946d56c74384511a194dd01dbe099584fd1a (patch) | |
tree | fd0bcea490dd81327ddfbb31e215439672c9a068 /test/fixedbugs/bug424.dir/main.go | |
parent | Initial commit. (diff) | |
download | golang-1.16-73df946d56c74384511a194dd01dbe099584fd1a.tar.xz golang-1.16-73df946d56c74384511a194dd01dbe099584fd1a.zip |
Adding upstream version 1.16.10.upstream/1.16.10upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/fixedbugs/bug424.dir/main.go')
-rw-r--r-- | test/fixedbugs/bug424.dir/main.go | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/test/fixedbugs/bug424.dir/main.go b/test/fixedbugs/bug424.dir/main.go new file mode 100644 index 0000000..28b41e6 --- /dev/null +++ b/test/fixedbugs/bug424.dir/main.go @@ -0,0 +1,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") + } +} |