Commit 4637699e authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile/internal/syntax: better error message for incorrect if/switch header

Fixes #23664.

Change-Id: Ic0637e9f896b2fc6502dfbab2d1c4de3c62c0bd2
Reviewed-on: https://go-review.googlesource.com/104616Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
parent a818ddd9
...@@ -1824,7 +1824,8 @@ func (p *parser) header(keyword token) (init SimpleStmt, cond Expr, post SimpleS ...@@ -1824,7 +1824,8 @@ func (p *parser) header(keyword token) (init SimpleStmt, cond Expr, post SimpleS
semi.lit = p.lit semi.lit = p.lit
p.next() p.next()
} else { } else {
p.want(_Semi) // asking for a '{' rather than a ';' here leads to a better error message
p.want(_Lbrace)
} }
if keyword == _For { if keyword == _For {
if p.tok != _Semi { if p.tok != _Semi {
......
// errorcheck
// Copyright 2018 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.
// Verify error messages for incorrect if/switch headers.
package p
func f() {
if f() true { // ERROR "unexpected true, expecting {"
}
switch f() true { // ERROR "unexpected true, 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