[dev.typeparams] Handling multiple type arguments for call via new node OLIST

Will now run "go tool compile -G=2 -W=2" on a simple generic function
with multiple type parameters and a call to that function with multiple
explicit type arguments.

We will likely move to have a separate function/type instantiation node,
in order distinguish these cases from normal index expressions.

Change-Id: I0a571902d63785cc06240ed4ba0495923403b511
Reviewed-on: https://go-review.googlesource.com/c/go/+/288433
Trust: Dan Scales <danscales@google.com>
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-01-30 21:15:40 -08:00
parent 13a7412983
commit 3d5c715bf2
6 changed files with 149 additions and 95 deletions

View file

@ -118,12 +118,11 @@ func Call(pos src.XPos, typ *types.Type, fun ir.Node, args []ir.Node, dots bool)
var targs []ir.Node
if indexExpr, ok := fun.(*ir.IndexExpr); ok {
if indexExpr.Index.Op() == ir.OTYPE {
if indexExpr.Index.Op() == ir.OLIST {
// Called function is an instantiated generic function
// TODO this handles just one type argument for now
fun = indexExpr.X
targs = make([]ir.Node, 1, 1)
targs[0] = indexExpr.Index
// Don't need to copy, since the node list was just created
targs = indexExpr.Index.(*ir.ListExpr).List
}
}
@ -235,7 +234,7 @@ func method(typ *types.Type, index int) *types.Field {
}
func Index(pos src.XPos, typ *types.Type, x, index ir.Node) ir.Node {
if index.Op() == ir.OTYPE {
if index.Op() == ir.OLIST {
n := ir.NewIndexExpr(pos, x, index)
typed(typ, n)
return n