Skip to content

Commit 6eb0f54

Browse files
griesemerrsc
authored andcommitted
[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 <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Reviewed-on: https://go-review.googlesource.com/36424 Run-TryBot: Russ Cox <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent c543cc3 commit 6eb0f54

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/cmd/compile/internal/syntax/parser.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,8 @@ func (p *parser) stmtBody(context string) []Stmt {
16341634
return body
16351635
}
16361636

1637+
var dummyCond = &Name{Value: "false"}
1638+
16371639
func (p *parser) header(forStmt bool) (init SimpleStmt, cond Expr, post SimpleStmt) {
16381640
if p.tok == _Lbrace {
16391641
return
@@ -1680,12 +1682,8 @@ func (p *parser) header(forStmt bool) (init SimpleStmt, cond Expr, post SimpleSt
16801682
case *ExprStmt:
16811683
cond = s.X
16821684
default:
1683-
// Not obviously a syntax error but by making it one, we get
1684-
// automatic filtering of multiple syntax error messages per
1685-
// line in the compiler. This avoids the follow-up error
1686-
// "missing condition in if statement" for an if statement
1687-
// (minimal fix for #18915).
16881685
p.syntax_error(fmt.Sprintf("%s used as value", String(s)))
1686+
cond = dummyCond // avoid follow-up error for if statements
16891687
}
16901688

16911689
p.xnest = outer

0 commit comments

Comments
 (0)