cmd/compile: fix missing transformEarlyCall for OXDOT in subster.node

Like OFUNCINST, in case of OXDOT call expression, the arguments need
to be transformed earlier, so any needed CONVIFACE nodes are exposed.

Fixes #49538

Change-Id: I275ddf6f53a9cadc8708e805941cdf7bdffabba9
Reviewed-on: https://go-review.googlesource.com/c/go/+/363554
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
This commit is contained in:
Cuong Manh Le 2021-11-12 13:27:07 +07:00
parent 5d24203c39
commit b1b6d928bd
2 changed files with 31 additions and 4 deletions

View file

@ -1095,6 +1095,9 @@ func (subst *subster) node(n ir.Node) ir.Node {
case ir.OXDOT:
// This is the case of a bound call on a typeparam,
// which will be handled in the dictPass.
// As with OFUNCINST, we must transform the arguments of the call now,
// so any needed CONVIFACE nodes are exposed.
transformEarlyCall(call)
case ir.ODOTTYPE, ir.ODOTTYPE2:
// These are DOTTYPEs that could get transformed into
@ -1229,14 +1232,15 @@ func (g *genInst) dictPass(info *instInfo) {
transformDot(mse, false)
}
case ir.OCALL:
op := m.(*ir.CallExpr).X.Op()
call := m.(*ir.CallExpr)
op := call.X.Op()
if op == ir.OMETHVALUE {
// Redo the transformation of OXDOT, now that we
// know the method value is being called.
m.(*ir.CallExpr).X.(*ir.SelectorExpr).SetOp(ir.OXDOT)
transformDot(m.(*ir.CallExpr).X.(*ir.SelectorExpr), true)
call.X.(*ir.SelectorExpr).SetOp(ir.OXDOT)
transformDot(call.X.(*ir.SelectorExpr), true)
}
transformCall(m.(*ir.CallExpr))
transformCall(call)
case ir.OCONVIFACE:
if m.Type().IsEmptyInterface() && m.(*ir.ConvExpr).X.Type().IsEmptyInterface() {

View file

@ -0,0 +1,23 @@
// compile -G=3
// Copyright 2021 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 p
type I interface {
M(interface{})
}
type a[T any] struct{}
func (a[T]) M(interface{}) {}
func f[T I](t *T) {
(*t).M(t)
}
func g() {
f(&a[int]{})
}