]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix missing transformEarlyCall for OXDOT in subster.node
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 12 Nov 2021 06:27:07 +0000 (13:27 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 12 Nov 2021 18:57:22 +0000 (18:57 +0000)
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>
src/cmd/compile/internal/noder/stencil.go
test/typeparam/issue49538.go [new file with mode: 0644]

index 20197565f544af8acf13c3aa3064375d7dac9254..4f9f8107bc2d214ba802ba67bd790fa3cb0a8e31 100644 (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() {
diff --git a/test/typeparam/issue49538.go b/test/typeparam/issue49538.go
new file mode 100644 (file)
index 0000000..ac20a54
--- /dev/null
@@ -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]{})
+}