aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/parser.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2017-02-06 15:08:28 -0800
committerRobert Griesemer <gri@golang.org>2017-02-06 23:33:07 +0000
commit3b68a647696ebfb61d199155f5f1faa5740e5c55 (patch)
tree07bc1ecd423b0a9025a7384c27774138603846a2 /src/cmd/compile/internal/syntax/parser.go
parent6a29440dcc5b71ded72d35e00a26d96c401f49d4 (diff)
downloadgo-3b68a647696ebfb61d199155f5f1faa5740e5c55.tar.xz
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>
Diffstat (limited to 'src/cmd/compile/internal/syntax/parser.go')
-rw-r--r--src/cmd/compile/internal/syntax/parser.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go
index fd16f580fb..bebcbb14de 100644
--- a/src/cmd/compile/internal/syntax/parser.go
+++ b/src/cmd/compile/internal/syntax/parser.go
@@ -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