aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2017-02-06 22:01:07 -0800
committerRuss Cox <rsc@golang.org>2017-02-07 16:52:00 +0000
commit6eb0f5440e7034235544001faa675a0945a1ba7b (patch)
treec32bb2de64117bfe2651f0bfea293f8f61b0457e
parentc543cc353deb4cffe213be5b094c8357faecab07 (diff)
downloadgo-6eb0f5440e7034235544001faa675a0945a1ba7b.tar.gz
go-6eb0f5440e7034235544001faa675a0945a1ba7b.zip
[release-branch.go1.8] cmd/compile/internal/syntax: avoid follow-up error for incorrect if statement
This is a follow-up on https://go-review.googlesource.com/36470 and leads to a more stable fix. The above CL relied on filtering of multiple errors on the same line to avoid more than one error for an `if` statement of the form `if a := 10 {}`. This CL avoids the secondary error ("missing condition in if statement") in the first place. For #18915. Change-Id: I8517f485cc2305965276c17d8f8797d61ef9e999 Reviewed-on: https://go-review.googlesource.com/36479 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-on: https://go-review.googlesource.com/36424 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
-rw-r--r--src/cmd/compile/internal/syntax/parser.go8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go
index 92eae0a458..e45ca05fd1 100644
--- a/src/cmd/compile/internal/syntax/parser.go
+++ b/src/cmd/compile/internal/syntax/parser.go
@@ -1634,6 +1634,8 @@ func (p *parser) stmtBody(context string) []Stmt {
return body
}
+var dummyCond = &Name{Value: "false"}
+
func (p *parser) header(forStmt bool) (init SimpleStmt, cond Expr, post SimpleStmt) {
if p.tok == _Lbrace {
return
@@ -1680,12 +1682,8 @@ func (p *parser) header(forStmt bool) (init SimpleStmt, cond Expr, post SimpleSt
case *ExprStmt:
cond = s.X
default:
- // 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)))
+ cond = dummyCond // avoid follow-up error for if statements
}
p.xnest = outer