[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>
This commit is contained in:
Dan Scales 2021-02-09 15:13:19 -08:00
parent 12e15d430d
commit fdf3496fcc
3 changed files with 33 additions and 27 deletions

View file

@ -84,6 +84,11 @@ func Call(pos src.XPos, typ *types.Type, fun ir.Node, args []ir.Node, dots bool)
if fun.Op() == ir.OTYPE {
// Actually a type conversion, not a function call.
n := ir.NewCallExpr(pos, ir.OCALL, fun, args)
if fun.Type().Kind() == types.TTYPEPARAM {
// For type params, don't typecheck until we actually know
// the type.
return typed(typ, n)
}
return typecheck.Expr(n)
}