mirror of
https://github.com/golang/go.git
synced 2025-10-23 21:13:20 +00:00
[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:
parent
13a7412983
commit
3d5c715bf2
6 changed files with 149 additions and 95 deletions
|
|
@ -99,10 +99,23 @@ func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node {
|
|||
}
|
||||
return Call(pos, g.typ(typ), g.expr(expr.Fun), g.exprs(expr.ArgList), expr.HasDots)
|
||||
case *syntax.IndexExpr:
|
||||
var index ir.Node
|
||||
|
||||
// We are using IndexExpr in two ways, as an standard index
|
||||
// operation (with expression) and as a function/type
|
||||
// instantiation (with a type list). We will soon make this
|
||||
// clearer by having separate function/type instantiation nodes.
|
||||
if _, ok := expr.Index.(*syntax.ListExpr); ok {
|
||||
panic("more than one type argument")
|
||||
// List of types for a generic function call or type instantiation
|
||||
index = ir.NewListExpr(pos, g.exprList(expr.Index))
|
||||
} else {
|
||||
index = g.expr(expr.Index)
|
||||
if index.Op() == ir.OTYPE {
|
||||
// Single type for a generic function call or type instantiation
|
||||
index = ir.NewListExpr(pos, []ir.Node{index})
|
||||
}
|
||||
}
|
||||
return Index(pos, g.typ(typ), g.expr(expr.X), g.expr(expr.Index))
|
||||
return Index(pos, g.typ(typ), g.expr(expr.X), index)
|
||||
case *syntax.ParenExpr:
|
||||
return g.expr(expr.X) // skip parens; unneeded after parse+typecheck
|
||||
case *syntax.SelectorExpr:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue