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

Closed
griesemer opened this issue Dec 15, 2020 · 5 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@griesemer
Copy link
Contributor

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 the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Dec 15, 2020
@griesemer griesemer added this to the Go1.17 milestone Dec 15, 2020
@griesemer griesemer self-assigned this Dec 15, 2020
@gopherbot
Copy link

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

cc: @ianlancetaylor for input on what gccgo does.

@ianlancetaylor
Copy link
Contributor

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

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

Change https://golang.org/cl/314411 mentions this issue: spec: clarify conditions for switch expression value

@golang golang locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

3 participants