summaryrefslogtreecommitdiff
path: root/src/go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2014-09-08 14:54:00 -0700
committerRobert Griesemer <gri@golang.org>2014-09-08 14:54:00 -0700
commit170b182a5ca379c8e1549cd63f961696f6886638 (patch)
treeba95878cfdf1541785e1e9091282c268960b98f5 /src/go
parenta2257035edf79f30bc5e7d1a0eadedb5d357059f (diff)
downloadgo-170b182a5ca379c8e1549cd63f961696f6886638.tar.gz
go/parser: fix (pathological) corner case
Inside a control clause (if ... {}), composite literals starting with a type name must be parenthesized. A composite literal used in the array length expression of an array composite literal is already parenthesized. Not a valid program, but syntactically is should be accepted. LGTM=adonovan R=adonovan CC=golang-codereviews https://codereview.appspot.com/142760043
Diffstat (limited to 'src/go')
-rw-r--r--src/go/parser/parser.go2
-rw-r--r--src/go/parser/short_test.go1
2 files changed, 3 insertions, 0 deletions
diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go
index 9c62076f2..4a005d8ff 100644
--- a/src/go/parser/parser.go
+++ b/src/go/parser/parser.go
@@ -641,6 +641,7 @@ func (p *parser) parseArrayType() ast.Expr {
}
lbrack := p.expect(token.LBRACK)
+ p.exprLev++
var len ast.Expr
// always permit ellipsis for more fault-tolerant parsing
if p.tok == token.ELLIPSIS {
@@ -649,6 +650,7 @@ func (p *parser) parseArrayType() ast.Expr {
} else if p.tok != token.RBRACK {
len = p.parseRhs()
}
+ p.exprLev--
p.expect(token.RBRACK)
elt := p.parseType()
diff --git a/src/go/parser/short_test.go b/src/go/parser/short_test.go
index f861086dd..05e44de28 100644
--- a/src/go/parser/short_test.go
+++ b/src/go/parser/short_test.go
@@ -39,6 +39,7 @@ var valids = []string{
`package p; func ((*T),) m() {}`,
`package p; func (*(T),) m() {}`,
`package p; func _(x []int) { for range x {} }`,
+ `package p; func _() { if [T{}.n]int{} {} }`,
}
func TestValid(t *testing.T) {