aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/reflectdata/reflect.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-06-18 14:09:21 -0700
committerDan Scales <danscales@google.com>2021-06-23 23:38:05 +0000
commitee4fc0c1bc300f181388ef6dd187ca8b8737efd2 (patch)
treed769935547e6a87112d17809239e3b06f82f90b3 /src/cmd/compile/internal/reflectdata/reflect.go
parent8165256bc2e3298b0d612471d7d2e6c005b984de (diff)
downloadgo-ee4fc0c1bc300f181388ef6dd187ca8b8737efd2.tar.gz
go-ee4fc0c1bc300f181388ef6dd187ca8b8737efd2.zip
[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 <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/reflectdata/reflect.go')
-rw-r--r--src/cmd/compile/internal/reflectdata/reflect.go13
1 files changed, 11 insertions, 2 deletions
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())...)