aboutsummaryrefslogtreecommitdiff
path: root/src/go/parser/parser.go
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2021-02-16 19:56:38 -0500
committerRobert Findley <rfindley@google.com>2021-02-18 20:38:41 +0000
commit5ecb9a788716be799d73c5d8192368ecb9557d48 (patch)
treec7909d74c3a563816463aa0728fd0904a905b2bc /src/go/parser/parser.go
parent7b679617f3bb532fe65d8e83365b9f1f41b01b00 (diff)
downloadgo-5ecb9a788716be799d73c5d8192368ecb9557d48.tar.gz
go-5ecb9a788716be799d73c5d8192368ecb9557d48.zip
[dev.typeparams] go/types: use a new ast.ListExpr for multi-type instances
Modify go/parser to consistently represent type instantiation as an ast.IndexExpr, rather than use an ast.CallExpr (with Brackets:true) for instantiations with multiple type parameters. To enable this, introduce a new ast expr type: ListExpr. This brings go/types in line with types2, with the exception of a small change to funcInst to eliminate redundant errors if values are erroneously used as types. In a subsequent CL, call.go and expr.go will be marked as reviewed. This also catches some type instance syntax using '()' that was previously accepted incorrectly. Tests are updated accordingly. Change-Id: I30cd0181c7608f1be7486a9a8b63df993b412e85 Reviewed-on: https://go-review.googlesource.com/c/go/+/293010 Trust: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/go/parser/parser.go')
-rw-r--r--src/go/parser/parser.go15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go
index ccbcef8f26..e12eee79bf 100644
--- a/src/go/parser/parser.go
+++ b/src/go/parser/parser.go
@@ -754,7 +754,7 @@ func (p *parser) parseArrayFieldOrTypeInstance(x *ast.Ident) (*ast.Ident, ast.Ex
}
// x[P], x[P1, P2], ...
- return nil, &ast.CallExpr{Fun: x, Lparen: lbrack, Args: args, Rparen: rbrack, Brackets: true}
+ return nil, &ast.IndexExpr{X: x, Lbrack: lbrack, Index: &ast.ListExpr{ElemList: args}, Rbrack: rbrack}
}
func (p *parser) parseFieldDecl(scope *ast.Scope) *ast.Field {
@@ -1153,7 +1153,7 @@ func (p *parser) parseMethodSpec(scope *ast.Scope) *ast.Field {
p.exprLev--
}
rbrack := p.expectClosing(token.RBRACK, "type argument list")
- typ = &ast.CallExpr{Fun: ident, Lparen: lbrack, Args: list, Rparen: rbrack, Brackets: true}
+ typ = &ast.IndexExpr{X: ident, Lbrack: lbrack, Index: &ast.ListExpr{ElemList: list}, Rbrack: rbrack}
}
case p.tok == token.LPAREN:
// ordinary method
@@ -1281,7 +1281,7 @@ func (p *parser) parseTypeInstance(typ ast.Expr) ast.Expr {
closing := p.expectClosing(token.RBRACK, "type argument list")
- return &ast.CallExpr{Fun: typ, Lparen: opening, Args: list, Rparen: closing, Brackets: true}
+ return &ast.IndexExpr{X: typ, Lbrack: opening, Index: &ast.ListExpr{ElemList: list}, Rbrack: closing}
}
// If the result is an identifier, it is not resolved.
@@ -1557,7 +1557,7 @@ func (p *parser) parseIndexOrSliceOrInstance(x ast.Expr) ast.Expr {
}
// instance expression
- return &ast.CallExpr{Fun: x, Lparen: lbrack, Args: args, Rparen: rbrack, Brackets: true}
+ return &ast.IndexExpr{X: x, Lbrack: lbrack, Index: &ast.ListExpr{ElemList: args}, Rbrack: rbrack}
}
func (p *parser) parseCallOrConversion(fun ast.Expr) *ast.CallExpr {
@@ -1773,17 +1773,12 @@ func (p *parser) parsePrimaryExpr(lhs bool) (x ast.Expr) {
// type; accept it but complain if we have a complit
t := unparen(x)
// determine if '{' belongs to a composite literal or a block statement
- switch t := t.(type) {
+ switch t.(type) {
case *ast.BadExpr, *ast.Ident, *ast.SelectorExpr:
if p.exprLev < 0 {
return
}
// x is possibly a composite literal type
- case *ast.CallExpr:
- if !t.Brackets || p.exprLev < 0 {
- return
- }
- // x is possibly a composite literal type
case *ast.IndexExpr:
if p.exprLev < 0 {
return