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

spec: unclear whether error should be reported for non-comparable switch expression in empty switch #43200

Open
griesemer opened this issue Dec 15, 2020 · 4 comments
Assignees
Labels
Milestone

Comments

@griesemer
Copy link
Contributor

@griesemer griesemer commented Dec 15, 2020

For:

var a struct{ _ func() }
switch a {
}

the compiler reports an error:

cannot switch on a (type struct { _ func() }) (struct containing func() cannot be compared)

Since there's no case in the switch statement, this might be considered ok. The spec is not explicitly stating that this is invalid.

See also #43110.

@griesemer griesemer added this to the Go1.17 milestone Dec 15, 2020
@griesemer griesemer self-assigned this Dec 15, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Dec 15, 2020

Change https://golang.org/cl/278132 mentions this issue: [dev.typeparams] cmd/compile/internal/types2: report error for invalid (but empty) expr switch

gopherbot pushed a commit that referenced this issue Dec 15, 2020
…d (but empty) expr switch

Enable one more errorcheck test.

Updates #43110.
Updates #43200.

Change-Id: Ib7b971d5e9989c65320579f75d65266bbbbeec53
Reviewed-on: https://go-review.googlesource.com/c/go/+/278132
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@griesemer
Copy link
Contributor Author

@griesemer griesemer commented Dec 15, 2020

cc: @ianlancetaylor for input on what gccgo does.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Dec 15, 2020

gccgo says

foo7.go:5:16: error: cannot switch on value whose type that may not be compared
    5 |         switch a {
      |                ^

So the message needs a little work but it has the same behavior.

@gopherbot
Copy link

@gopherbot gopherbot commented Dec 15, 2020

Change https://golang.org/cl/278452 mentions this issue: compiler: correct grammar in error message

gopherbot pushed a commit to golang/gofrontend that referenced this issue Dec 15, 2020
For golang/go#43200

Change-Id: I7f102bfdd5a2578e59292be4c84e11df107f65c6
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/278452
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.