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: confusing error trying to increment boolean value #12525

Closed
davecheney opened this issue Sep 7, 2015 · 4 comments
Closed

cmd/compile: confusing error trying to increment boolean value #12525

davecheney opened this issue Sep 7, 2015 · 4 comments

Comments

@davecheney
Copy link
Contributor

package main

func main() {
    var x bool
    x++
}
prog.go:5: cannot convert 1 to type bool
prog.go:5: invalid operation: x++ (non-numeric type bool)

The first error should be suppressed.

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Sep 8, 2015
@rsc
Copy link
Contributor

rsc commented Dec 5, 2015

Would be nice but we won't get to it for Go 1.6.

@rsc rsc modified the milestones: Unplanned, Go1.6 Dec 5, 2015
@gopherbot
Copy link

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

@gopherbot
Copy link

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

@cmarcelo
Copy link
Contributor

cmarcelo commented Mar 7, 2016

@griesemer https://go-review.googlesource.com/#/c/20244/ is a similar change for go/types.

gopherbot pushed a commit that referenced this issue Mar 7, 2016
In increment and decrement statements, explicit check that the type
of operand is numeric. This avoids a related but less clear error
about converting "1" to be emitted.

So, when checking

	package main

	func main() {
		var x bool
		x++
	}

instead of emitting the error

	prog.go:5:2: cannot convert 1 (untyped int constant) to bool

emits

	prog.go:5:2: invalid operation: x++ (non-numeric type bool).

Updates #12525.

Change-Id: I00aa6bd0bb23267a2fe10ea3f5a0b20bbf3552bc
Reviewed-on: https://go-review.googlesource.com/20244
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Mar 13, 2017
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

5 participants