mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/syntax: make a parser error "1.7 compliant"
For code such as
if a := 10 { ...
the 1.7 compiler reported
a := 10 used as value
while the 1.8 compiler reported
invalid condition, tag, or type switch guard
Changed the error message to match the 1.7 compiler.
Fixes #18915.
Change-Id: I01308862e461922e717f9f8295a9db53d5a914eb
Reviewed-on: https://go-review.googlesource.com/36470
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
6a29440dcc
commit
3b68a64769
2 changed files with 27 additions and 1 deletions
|
|
@ -1746,7 +1746,12 @@ func (p *parser) header(forStmt bool) (init SimpleStmt, cond Expr, post SimpleSt
|
|||
case *ExprStmt:
|
||||
cond = s.X
|
||||
default:
|
||||
p.error("invalid condition, tag, or type switch guard")
|
||||
// Not obviously a syntax error but by making it one, we get
|
||||
// automatic filtering of multiple syntax error messages per
|
||||
// line in the compiler. This avoids the follow-up error
|
||||
// "missing condition in if statement" for an if statement
|
||||
// (minimal fix for #18915).
|
||||
p.syntax_error(fmt.Sprintf("%s used as value", String(s)))
|
||||
}
|
||||
|
||||
p.xnest = outer
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue