aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2016-11-28 22:34:50 -0800
committerRobert Griesemer <gri@golang.org>2016-11-29 16:47:34 +0000
commit8fa0d85b385b549fed163fe67342dfcd092e02c4 (patch)
tree8ba938b781c4f0a6a219b13c1a1f5895634504e2
parent6f287fa2bb5b0b74506ecc586d036dcd11a761e2 (diff)
downloadgo-8fa0d85b385b549fed163fe67342dfcd092e02c4.tar.gz
go-8fa0d85b385b549fed163fe67342dfcd092e02c4.zip
cmd/compile: don't panic on syntax error in select statement
Fixes #18092. Change-Id: I54e2da2e0f168c068f5e4a1b22ba508d78259168 Reviewed-on: https://go-review.googlesource.com/33658 TryBot-Result: Gobot Gobot <gobot@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
-rw-r--r--src/cmd/compile/internal/syntax/parser.go29
-rw-r--r--test/fixedbugs/issue18092.go15
2 files changed, 27 insertions, 17 deletions
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go
index 41e7cbe56d..a2e307f46f 100644
--- a/src/cmd/compile/internal/syntax/parser.go
+++ b/src/cmd/compile/internal/syntax/parser.go
@@ -1809,24 +1809,19 @@ func (p *parser) commClause() *CommClause {
switch p.tok {
case _Case:
p.next()
- lhs := p.exprList()
-
- if _, ok := lhs.(*ListExpr); !ok && p.tok == _Arrow {
- // lhs <- x
- } else {
- // lhs
- // lhs = <-x
- // lhs := <-x
- if p.tok == _Assign || p.tok == _Define {
- // TODO(gri) check that lhs has at most 2 entries
- } else if p.tok == _Colon {
- // TODO(gri) check that lhs has at most 1 entry
- } else {
- panic("unimplemented")
- }
- }
+ c.Comm = p.simpleStmt(nil, false)
- c.Comm = p.simpleStmt(lhs, false)
+ // The syntax restricts the possible simple statements here to:
+ //
+ // lhs <- x (send statement)
+ // <-x
+ // lhs = <-x
+ // lhs := <-x
+ //
+ // All these (and more) are recognized by simpleStmt and invalid
+ // syntax trees are flagged later, during type checking.
+ // TODO(gri) eventually may want to restrict valid syntax trees
+ // here.
case _Default:
p.next()
diff --git a/test/fixedbugs/issue18092.go b/test/fixedbugs/issue18092.go
new file mode 100644
index 0000000000..94fd2dd383
--- /dev/null
+++ b/test/fixedbugs/issue18092.go
@@ -0,0 +1,15 @@
+// errorcheck
+
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func _() {
+ var ch chan bool
+ select {
+ default:
+ case <-ch { // don't crash here
+ } // ERROR "expecting :"
+}