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

griesemer opened this issue Dec 15, 2020 · 4 comments


Copy link

@griesemer griesemer commented Dec 15, 2020


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

@gopherbot gopherbot commented Dec 15, 2020

Change 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
Trust: Robert Griesemer <>
Reviewed-by: Robert Findley <>
Copy link
Contributor Author

@griesemer griesemer commented Dec 15, 2020

cc: @ianlancetaylor for input on what gccgo does.

Copy link

@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.

Copy link

@gopherbot gopherbot commented Dec 15, 2020

Change 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
Trust: Ian Lance Taylor <>
Reviewed-by: Robert Griesemer <>
Reviewed-by: Than McIntosh <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.