Commit 8fa0d85b authored by Robert Griesemer's avatar Robert Griesemer

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: 's avatarMatthew Dempsky <mdempsky@google.com>
parent 6f287fa2
...@@ -1809,24 +1809,19 @@ func (p *parser) commClause() *CommClause { ...@@ -1809,24 +1809,19 @@ func (p *parser) commClause() *CommClause {
switch p.tok { switch p.tok {
case _Case: case _Case:
p.next() p.next()
lhs := p.exprList() c.Comm = p.simpleStmt(nil, false)
if _, ok := lhs.(*ListExpr); !ok && p.tok == _Arrow { // The syntax restricts the possible simple statements here to:
// lhs <- x //
} else { // lhs <- x (send statement)
// lhs // <-x
// lhs = <-x // lhs = <-x
// lhs := <-x // lhs := <-x
if p.tok == _Assign || p.tok == _Define { //
// TODO(gri) check that lhs has at most 2 entries // All these (and more) are recognized by simpleStmt and invalid
} else if p.tok == _Colon { // syntax trees are flagged later, during type checking.
// TODO(gri) check that lhs has at most 1 entry // TODO(gri) eventually may want to restrict valid syntax trees
} else { // here.
panic("unimplemented")
}
}
c.Comm = p.simpleStmt(lhs, false)
case _Default: case _Default:
p.next() p.next()
......
// 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 :"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment