Ian Lance Taylor | d3764dd | 2014-05-06 09:01:38 -0400 | [diff] [blame] | 1 | // run |
| 2 | |
Emmanuel Odeke | 53fd522 | 2016-04-10 14:32:26 -0700 | [diff] [blame] | 3 | // Copyright 2014 The Go Authors. All rights reserved. |
Ian Lance Taylor | d3764dd | 2014-05-06 09:01:38 -0400 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style |
| 5 | // license that can be found in the LICENSE file. |
| 6 | |
| 7 | // Gccgo chose the wrong embedded method when the same type appeared |
| 8 | // at different levels and the correct choice was not the first |
| 9 | // appearance of the type in a depth-first search. |
| 10 | |
| 11 | package main |
| 12 | |
| 13 | type embedded string |
| 14 | |
| 15 | func (s embedded) val() string { |
| 16 | return string(s) |
| 17 | } |
| 18 | |
| 19 | type A struct { |
| 20 | embedded |
| 21 | } |
| 22 | |
| 23 | type B struct { |
| 24 | A |
| 25 | embedded |
| 26 | } |
| 27 | |
| 28 | func main() { |
| 29 | b := &B{ |
| 30 | A: A{ |
| 31 | embedded: "a", |
| 32 | }, |
| 33 | embedded: "b", |
| 34 | } |
| 35 | s := b.val() |
| 36 | if s != "b" { |
| 37 | panic(s) |
| 38 | } |
| 39 | } |