From 69015b6fc467a9e0d5772794f15476da458d7cc5 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 27 Feb 2012 18:52:40 -0800 Subject: [PATCH] test: bug424: wrong embedded method called R=golang-dev, r CC=golang-dev https://golang.org/cl/5695083 --- test/bugs/424.dir/lib.go | 16 ++++++++++ test/bugs/424.dir/main.go | 61 +++++++++++++++++++++++++++++++++++++++ test/bugs/424.go | 9 ++++++ test/golden.out | 3 ++ 4 files changed, 89 insertions(+) create mode 100644 test/bugs/424.dir/lib.go create mode 100644 test/bugs/424.dir/main.go create mode 100644 test/bugs/424.go diff --git a/test/bugs/424.dir/lib.go b/test/bugs/424.dir/lib.go new file mode 100644 index 00000000000..97054da3a31 --- /dev/null +++ b/test/bugs/424.dir/lib.go @@ -0,0 +1,16 @@ +// 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. + +package lib + +type I interface { + m() string +} + +type T struct{} + +// m is not accessible from outside this package. +func (t *T) m() string { + return "lib.T.m" +} diff --git a/test/bugs/424.dir/main.go b/test/bugs/424.dir/main.go new file mode 100644 index 00000000000..64a600b5548 --- /dev/null +++ b/test/bugs/424.dir/main.go @@ -0,0 +1,61 @@ +// 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 the locally defined method localT.m independent +// at which embedding level it is and in which order +// embedding is done. + +package main + +import "./lib" + +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") + } + + i = new(myT3) + if i.m() != "main.localT.m" { + println("BUG: myT3:", i.m(), "called") + } + +} diff --git a/test/bugs/424.go b/test/bugs/424.go new file mode 100644 index 00000000000..b22776086e3 --- /dev/null +++ b/test/bugs/424.go @@ -0,0 +1,9 @@ +// $G $D/$F.dir/lib.go && $G $D/$F.dir/main.go && $L main.$A && $A.out + +// 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. + +// Test case for embedded method invocation. + +ignored diff --git a/test/golden.out b/test/golden.out index 764f561969d..b7d759450cf 100644 --- a/test/golden.out +++ b/test/golden.out @@ -17,5 +17,8 @@ == bugs/ +=========== bugs/424.go +BUG: myT3: lib.T.m called + =========== bugs/bug395.go bug395 is broken