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