[dev.typeparams] cmd/compile: allow conversions from type parameter to interface

When converting from a type param to an interface, allow it if
the type bound implements that interface.

Query: some conversions go through this path, some use another path?
The test does

   var i interface{foo()int} = x

but

   i := (interface{foo()int})(x)

works at tip.

Change-Id: I84d497e5228c0e1d1c9d76ffebaedce09dc45e8e
Reviewed-on: https://go-review.googlesource.com/c/go/+/325409
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
This commit is contained in:
Keith Randall 2021-06-04 22:54:08 -07:00
parent bcb3927cb5
commit cf4b6dc48e
3 changed files with 73 additions and 2 deletions

View file

@ -437,7 +437,10 @@ func assignconvfn(n ir.Node, t *types.Type) ir.Node {
return n
}
op, _ := typecheck.Assignop(n.Type(), t)
op, why := typecheck.Assignop(n.Type(), t)
if op == ir.OXXX {
base.Fatalf("found illegal assignment %+v -> %+v; %s", n.Type(), t, why)
}
r := ir.NewConvExpr(base.Pos, op, t, n)
r.SetTypecheck(1)