diff options
| author | Dan Scales <danscales@google.com> | 2021-02-09 15:13:19 -0800 |
|---|---|---|
| committer | Dan Scales <danscales@google.com> | 2021-02-10 03:33:05 +0000 |
| commit | fdf3496fccfd5c5593ac9e03804ffc8feeb59dbc (patch) | |
| tree | bbe6ab26a31903dcb678a5aff466ca31b2238d8f /src/cmd/compile/internal/noder/stencil.go | |
| parent | 12e15d430d408ff9a961bdfb72cfc7f0b521a354 (diff) | |
| download | go-fdf3496fccfd5c5593ac9e03804ffc8feeb59dbc.tar.xz | |
[dev.typeparams] cmd/compile: make type conversions by type parameters work
When doing a type conversion using a type param, delay the
transformation to OCONV/OCONVNOP until stenciling, since the nodes
created depend on the actual type.
Re-enable the fact.go test.
Change-Id: I3d5861aab3dd0e781d767f67435afaf951dfe451
Reviewed-on: https://go-review.googlesource.com/c/go/+/290752
Trust: Dan Scales <danscales@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/noder/stencil.go')
| -rw-r--r-- | src/cmd/compile/internal/noder/stencil.go | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index 64320237d9..2995496da1 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -174,30 +174,36 @@ func (subst *subster) node(n ir.Node) ir.Node { } ir.EditChildren(m, edit) - // A method value/call via a type param will have been left as an - // OXDOT. When we see this during stenciling, finish the - // typechecking, now that we have the instantiated receiver type. - // We need to do this now, since the access/selection to the - // method for the real type is very different from the selection - // for the type param. if x.Op() == ir.OXDOT { - // Will transform to an OCALLPART + // A method value/call via a type param will have been left as an + // OXDOT. When we see this during stenciling, finish the + // typechecking, now that we have the instantiated receiver type. + // We need to do this now, since the access/selection to the + // method for the real type is very different from the selection + // for the type param. m.SetTypecheck(0) + // m will transform to an OCALLPART typecheck.Expr(m) } if x.Op() == ir.OCALL { call := m.(*ir.CallExpr) - if call.X.Op() != ir.OCALLPART { - base.FatalfAt(call.Pos(), "Expecting OXDOT with CALL") + if call.X.Op() == ir.OTYPE { + // Do typechecking on a conversion, now that we + // know the type argument. + m.SetTypecheck(0) + m = typecheck.Expr(m) + } else if call.X.Op() == ir.OCALLPART { + // Redo the typechecking, now that we know the method + // value is being called. + call.X.(*ir.SelectorExpr).SetOp(ir.OXDOT) + call.X.SetTypecheck(0) + call.X.SetType(nil) + typecheck.Callee(call.X) + m.SetTypecheck(0) + typecheck.Call(m.(*ir.CallExpr)) + } else { + base.FatalfAt(call.Pos(), "Expecting OCALLPART or OTYPE with CALL") } - // Redo the typechecking, now that we know the method - // value is being called - call.X.(*ir.SelectorExpr).SetOp(ir.OXDOT) - call.X.SetTypecheck(0) - call.X.SetType(nil) - typecheck.Callee(call.X) - m.SetTypecheck(0) - typecheck.Call(m.(*ir.CallExpr)) } if x.Op() == ir.OCLOSURE { |
