Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: improve error message when if statement brace is on next line #18747

Closed
go101 opened this issue Jan 22, 2017 · 11 comments
Closed

cmd/compile: improve error message when if statement brace is on next line #18747

go101 opened this issue Jan 22, 2017 · 11 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@go101
Copy link

go101 commented Jan 22, 2017

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.

@mvdan
Copy link
Member

mvdan commented 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

@josharian josharian changed the title error message needs improving cmd/compile: improve error message when if statement brace is on next line Jan 22, 2017
@josharian
Copy link
Contributor

@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
Copy link
Member

mvdan commented Jan 22, 2017

@josharian did you mean that triage sentence towards me? I haven't requested github access, maybe I should.

@josharian
Copy link
Contributor

It was meant for @golang101. But you should definitely request GitHub access.

@bradfitz bradfitz added this to the Go1.9 milestone Jan 22, 2017
@bradfitz bradfitz added the NeedsFix The path to resolution is known, but the work has not been done. label Jan 22, 2017
@go101
Copy link
Author

go101 commented Jan 23, 2017

@josharian I would like to.

@gopherbot
Copy link

CL https://golang.org/cl/36317 mentions this issue.

@mdempsky
Copy link
Member

mdempsky commented Feb 4, 2017

Syntactically,

if foo
{
}

is the same as

if foo; {}

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
Copy link
Contributor

bradfitz commented 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
Copy link
Member

odeke-em commented 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.

if condition
{
}

wasn't intuitive since visually they already provided the condition a == 1

Getting the same message for

if expression; {
}

that tells me to think about the missing condition in the style

if expression; condition {

even though expression might be a condition.

espadrine added a commit to espadrine/go that referenced this issue Feb 8, 2017
espadrine added a commit to espadrine/go that referenced this issue Feb 9, 2017
… line

A typical beginner mistake is to place the left brace on a new line:

	if condition
	{
		...
	}

Prior to this commit, the error message was misleading:

	missing condition in if statement

Switch to a better error message:

	missing { after if clause

Fixes golang#18747.
@gopherbot
Copy link

CL https://golang.org/cl/36930 mentions this issue.

gopherbot pushed a commit that referenced this issue Feb 13, 2017
Use distinction between explicit and automatically inserted semicolons
to provide a better error message if the condition in an 'if' statement
is missing.

For #18747.

Change-Id: Iac167ae4e5ad53d2dc73f746b4dee9912434bb59
Reviewed-on: https://go-review.googlesource.com/36930
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
@griesemer
Copy link
Contributor

This was fixed by https://go-review.googlesource.com/#/c/36930/.

@golang golang locked and limited conversation to collaborators Feb 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

8 participants