aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/expr.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-01-30 21:15:40 -0800
committerDan Scales <danscales@google.com>2021-02-02 19:14:08 +0000
commit3d5c715bf299fb662104d70d612f3f0303e542d9 (patch)
tree00a3f165808fd0f7c4d31ab69b15b13339a06a29 /src/cmd/compile/internal/noder/expr.go
parent13a741298377d30fc2b3fc51fa9aa52eed6d56e4 (diff)
downloadgo-3d5c715bf299fb662104d70d612f3f0303e542d9.tar.gz
go-3d5c715bf299fb662104d70d612f3f0303e542d9.zip
[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>
Diffstat (limited to 'src/cmd/compile/internal/noder/expr.go')
-rw-r--r--src/cmd/compile/internal/noder/expr.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/noder/expr.go b/src/cmd/compile/internal/noder/expr.go
index 79b94638e8..41d54441d4 100644
--- a/src/cmd/compile/internal/noder/expr.go
+++ b/src/cmd/compile/internal/noder/expr.go
@@ -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: