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

go/types, types2: missing error for invalid (but empty) expression switch #43110

Closed
griesemer opened this issue Dec 10, 2020 · 2 comments
Closed

go/types, types2: missing error for invalid (but empty) expression switch #43110

griesemer opened this issue Dec 10, 2020 · 2 comments
Assignees
Labels
Milestone

Comments

@griesemer
Copy link
Contributor

@griesemer griesemer commented Dec 10, 2020

For

package main

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

the compiler reports

main.go:5:2: cannot switch on a (type struct { _ func() }) (struct containing func() cannot be compared)

go/types and types2 don't report an error.

For

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

go/types and types2 report an error with case a:

main.go:6:7: cannot compare a == a (operator == not defined for struct{_ func()})

Empty switches like this are unlikely, but we should report an error at the top (and than avoid the respective errors for the cases).

cc: @findleyr

@griesemer griesemer added this to the Go1.17 milestone Dec 10, 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

Loading

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

@gopherbot gopherbot commented Dec 16, 2020

Change https://golang.org/cl/278813 mentions this issue: go/types: report error for invalid (but empty) expr switch

Loading

@gopherbot gopherbot closed this in b0f01e1 Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants