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
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@griesemer
Copy link
Contributor

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 the NeedsFix The path to resolution is known, but the work has not been done. label Dec 10, 2020
@griesemer griesemer added this to the Go1.17 milestone Dec 10, 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>
@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants