You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/compile: improve error message when if statement brace is on next line #18747
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go version go1.7.4 linux/amd64
What did you do?
package main
func main() {
a := 1
for a = 1; a < 2; a++ // syntax error: missing { after for clause
{
}
if a == 1 // missing condition in if statement
{
}
}
What did you expect to see?
the two error messages should be alike.
What did you see instead?
the the second error message is not very accurate.
@golang101 thanks for filing issues. Would you mind helping the folks doing triage by identifying the relevant component in the issue title, when you know it? Thanks!
And the latter produces a "missing condition in if statement" error, which is why the former does too.
It's not obvious that the former deserves a different error message; or that if it does, what exactly should be the criteria for producing something different. I'd like to establish that before we worry about CLs.
@mdempsky, I bet only about 2% of Go users know that semicolons are even in the language at all, much less know the insertion rules.
I personally think it deserves a better error message. A fair number of newcomers to the language are going to write code in that style before they discover gofmt.
Activity
mvdan commentedon Jan 22, 2017
Happens all the same on
go version devel +4cce27a3fa Sat Jan 21 03:20:55 2017 +0000 linux/amd64.@golang101 perhaps retitle to something like
cmd/compile: wrong error when the opening brace of an if is on a new line[-]error message needs improving[/-][+]cmd/compile: improve error message when if statement brace is on next line[/+]josharian commentedon Jan 22, 2017
@golang101 thanks for filing issues. Would you mind helping the folks doing triage by identifying the relevant component in the issue title, when you know it? Thanks!
cc @odeke-em
mvdan commentedon Jan 22, 2017
@josharian did you mean that triage sentence towards me? I haven't requested github access, maybe I should.
josharian commentedon Jan 22, 2017
It was meant for @golang101. But you should definitely request GitHub access.
zigo101 commentedon Jan 23, 2017
@josharian I would like to.
gopherbot commentedon Feb 4, 2017
CL https://golang.org/cl/36317 mentions this issue.
mdempsky commentedon Feb 4, 2017
Syntactically,
is the same as
And the latter produces a "missing condition in if statement" error, which is why the former does too.
It's not obvious that the former deserves a different error message; or that if it does, what exactly should be the criteria for producing something different. I'd like to establish that before we worry about CLs.
bradfitz commentedon Feb 4, 2017
@mdempsky, I bet only about 2% of Go users know that semicolons are even in the language at all, much less know the insertion rules.
I personally think it deserves a better error message. A fair number of newcomers to the language are going to write code in that style before they discover gofmt.
odeke-em commentedon Feb 4, 2017
@mdempsky, yeah, I agree with @bradfitz's explanation,
I too think it deserves a better error message.
As we can see in the issue report, the user who reported it found the same problem.
wasn't intuitive since visually they already provided the condition
a == 1Getting the same message for
that tells me to think about the missing condition in the style
even though
expressionmight be a condition.cmd/compile/internal/syntax: improve error message when if statement …
cmd/compile: improve error message when if statement brace is on next…
gopherbot commentedon Feb 13, 2017
CL https://golang.org/cl/36930 mentions this issue.
cmd/compile/internal/syntax: better error for malformed 'if' statements
griesemer commentedon Feb 15, 2017
This was fixed by https://go-review.googlesource.com/#/c/36930/.