Skip to content

Commit 2169deb

Browse files
committed
cmd/compile: use t.AllMethods when sorting typesByString
For interface types, t.Methods contains only unexpanded method set, i.e exclusive of interface embedding. Thus, we can't use it to detect an interface contains embedding empty interface, like in: type EI interface{} func f() interface{ EI } { return nil } At the time we generate runtime types, we want to check against the full method set of interface instead. Fixes #46386 Change-Id: Idff53ad39276be6632eb5932b76e855c15cbdd2e Reviewed-on: https://go-review.googlesource.com/c/go/+/323649 Trust: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent c20bcb6 commit 2169deb

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/cmd/compile/internal/reflectdata/reflect.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1475,8 +1475,8 @@ func (a typesByString) Less(i, j int) bool {
14751475
// will be equal for the above checks, but different in DWARF output.
14761476
// Sort by source position to ensure deterministic order.
14771477
// See issues 27013 and 30202.
1478-
if a[i].t.Kind() == types.TINTER && a[i].t.Methods().Len() > 0 {
1479-
return a[i].t.Methods().Index(0).Pos.Before(a[j].t.Methods().Index(0).Pos)
1478+
if a[i].t.Kind() == types.TINTER && a[i].t.AllMethods().Len() > 0 {
1479+
return a[i].t.AllMethods().Index(0).Pos.Before(a[j].t.AllMethods().Index(0).Pos)
14801480
}
14811481
return false
14821482
}

test/fixedbugs/issue46386.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// compile -p=main
2+
3+
// Copyright 2021 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+
package main
8+
9+
type I interface {
10+
M() interface{}
11+
}
12+
13+
type S1 struct{}
14+
15+
func (S1) M() interface{} {
16+
return nil
17+
}
18+
19+
type EI interface{}
20+
21+
type S struct{}
22+
23+
func (S) M(as interface{ I }) {}
24+
25+
func f() interface{ EI } {
26+
return &S1{}
27+
}
28+
29+
func main() {
30+
var i interface{ I }
31+
(&S{}).M(i)
32+
}

0 commit comments

Comments
 (0)