From ee4fc0c1bc300f181388ef6dd187ca8b8737efd2 Mon Sep 17 00:00:00 2001 From: Dan Scales Date: Fri, 18 Jun 2021 14:09:21 -0700 Subject: [dev.typeparams] Fix issues related to dictionaries and method calls with embedded fields - Fix handling of method expressions with embedded fields. Fix an incorrect lookup for method expressions, which have only the top-level type (and don't have DOT operations for the embedded fields). Add the embedded field dot operations into the closure. - Don't need a dictionary and so don't build a closure if the last embedded field reached in a method expression is an interface value. - Fix methodWrapper() to use the computed 'dot' node in the generic-only part of the code. - For a method expression, don't create a generic wrapper if the last embedded field reached before the method lookup is an interface. Copied cmd/compile/internal/types2/testdata/fixedbugs/issue44688.go2 to test/typeparam/issue44688.go, made it fully runnable (rather than just for compilation), and added a bunch more tests. Change-Id: I90c1aa569e1c7272e986c9d2ae683e553c3a38a1 Reviewed-on: https://go-review.googlesource.com/c/go/+/329550 Run-TryBot: Dan Scales TryBot-Result: Go Bot Trust: Dan Scales Reviewed-by: Keith Randall --- src/cmd/compile/internal/reflectdata/reflect.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/cmd/compile/internal/reflectdata/reflect.go') diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index 9e070895a0..52534db70d 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -1786,6 +1786,11 @@ func methodWrapper(rcvr *types.Type, method *types.Field, forItab bool) *obj.LSy } dot := typecheck.AddImplicitDots(ir.NewSelectorExpr(base.Pos, ir.OXDOT, nthis, method.Sym)) + if generic && dot.X != nthis && dot.X.Type().IsInterface() { + // We followed some embedded fields, and the last type was + // actually an interface, so no need for a dictionary. + generic = false + } // generate call // It's not possible to use a tail call when dynamic linking on ppc64le. The @@ -1824,9 +1829,13 @@ func methodWrapper(rcvr *types.Type, method *types.Field, forItab bool) *obj.LSy } args = append(args, getDictionary(".inst."+ir.MethodSym(orig, method.Sym).Name, targs)) // TODO: remove .inst. if indirect { - args = append(args, ir.NewStarExpr(base.Pos, nthis)) + args = append(args, ir.NewStarExpr(base.Pos, dot.X)) + } else if methodrcvr.IsPtr() && methodrcvr.Elem() == dot.X.Type() { + // Case where method call is via a non-pointer + // embedded field with a pointer method. + args = append(args, typecheck.NodAddrAt(base.Pos, dot.X)) } else { - args = append(args, nthis) + args = append(args, dot.X) } args = append(args, ir.ParamNames(tfn.Type())...) -- cgit v1.2.3-54-g00ecf