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: regressed error message for assignment used as value in if statement #18915

Closed
odeke-em opened this issue Feb 3, 2017 · 5 comments

Comments

@odeke-em
Copy link
Member

odeke-em commented Feb 3, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version devel +57546d6 Thu Feb 2 22:39:32 2017 +0000 darwin/amd64
Also reproducible on go1.8rc2, go1.8rc3 as well

What operating system and processor architecture are you using (go env)?

Irrelevant

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
I was hacking on a fix for #18747 and was just writing a test/fixedbugs/* test and noticed it.

Repro: https://play.golang.org/p/YnUHrPQPZW or below:

package main

func main() {
	if a := 10 {
	}
}

What did you expect to see?

main.go:4: a := 10 used as value

as it does for Go1.7

What did you see instead?

# command-line-arguments
./main.go:4: invalid condition, tag, or type switch guard
./main.go:4: syntax error: missing condition in if statement

Pre Go1.8:

  • the error message was clear and didn't have the extraneous wrong
    syntax error: missing condition in if statement.

IMO we should try to fix this bug for Go1.8, otherwise we are going to receive many bug reports
about folks complaining since the if {{assignment}}; {{comparison}} { style is code that
I see often, so it would be nice to have clear error messages related to it.

/cc the compiler squad @josharian @mdempsky @griesemer @randall77

@griesemer griesemer self-assigned this Feb 3, 2017
@griesemer griesemer added this to the Go1.8Maybe milestone Feb 3, 2017
@gopherbot
Copy link

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

@gopherbot
Copy link

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

@gopherbot
Copy link

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

gopherbot pushed a commit that referenced this issue Feb 7, 2017
…tatement

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 <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
@gopherbot
Copy link

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

@gopherbot
Copy link

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

gopherbot pushed a commit that referenced this issue Feb 7, 2017
…or "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>
Reviewed-on: https://go-review.googlesource.com/36422
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
gopherbot pushed a commit that referenced this issue Feb 7, 2017
…rror 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 <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-on: https://go-review.googlesource.com/36424
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
@golang golang locked and limited conversation to collaborators Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants