Skip to content

Commit 3969694

Browse files
cuonglmcherrymui
authored andcommitted
[release-branch.go1.17] cmd/compile: fix method expression lookup during import
CL 309831 fixed importing of method expressions, by re-using the same code already have for ODOTMETH. But that code does not work with embedded field. To fix this, we need to calculate all methods of the receiver base type of method expression, before looking up the selection. Fixes #48102 Change-Id: Ia244d36a3ed0f989735eb57becdfa70a81912f57 Reviewed-on: https://go-review.googlesource.com/c/go/+/346489 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]> Reviewed-on: https://go-review.googlesource.com/c/go/+/346670 Reviewed-by: Keith Randall <[email protected]>
1 parent 1dd24ca commit 3969694

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

src/cmd/compile/internal/typecheck/iimport.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,12 +1222,14 @@ func (r *importReader) node() ir.Node {
12221222
switch op {
12231223
case ir.ODOT, ir.ODOTPTR, ir.ODOTINTER:
12241224
n.Selection = r.exoticField()
1225-
case ir.ODOTMETH, ir.OCALLPART, ir.OMETHEXPR:
1225+
case ir.OMETHEXPR:
1226+
n = typecheckMethodExpr(n).(*ir.SelectorExpr)
1227+
case ir.ODOTMETH, ir.OCALLPART:
12261228
// These require a Lookup to link to the correct declaration.
12271229
rcvrType := expr.Type()
12281230
typ := n.Type()
12291231
n.Selection = Lookdot(n, rcvrType, 1)
1230-
if op == ir.OCALLPART || op == ir.OMETHEXPR {
1232+
if op == ir.OCALLPART {
12311233
// Lookdot clobbers the opcode and type, undo that.
12321234
n.SetOp(op)
12331235
n.SetType(typ)

test/fixedbugs/issue48088.dir/a.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package a
6+
7+
type T1 struct {
8+
*T2
9+
}
10+
11+
type T2 struct {
12+
}
13+
14+
func (t2 *T2) M() {
15+
}
16+
17+
func F() {
18+
f(T1.M)
19+
}
20+
21+
func f(f func(T1)) {
22+
}

test/fixedbugs/issue48088.dir/b.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package b
6+
7+
import "a"
8+
9+
func F() {
10+
a.F()
11+
}

test/fixedbugs/issue48088.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compiledir
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 ignored

0 commit comments

Comments
 (0)