-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed as not planned
Labels
questionFurther information is requestedFurther information is requested
Description
Welcome
- Yes, I've searched similar issues on GitHub and didn't find any.
- I agree to follow this project's Code of Conduct
Your feature request related to a problem? Please describe
When I create an enum, sometimes I want to use a struct for that enum. But if I do that, the exhaustive linter cannot check the exhaustiveness.
Describe the solution you'd like
Check the exhaustiveness for variables which are declared right after the type definition.
type Enum struct {s string}
var (
Enum1 = Enum{"1"}
Enum2 = Enum{"2"}
Enum3 = Enum{"3"}
)
var Enum4 = Enum{"4"}
func main() {
var enum Enum
switch enum {
case Enum1:
case Enum2:
}
// Expected: missing Enum3.
// Enum4 should be ignored.
}Describe alternatives you've considered
I think it should check the exhaustiveness for constants which are declared right after type definition, rather than for all constants.
type Enum int
coinst (
Enum1 Enum = iota
Enum2
Enum3
)
func main() {
var enum Enum
switch enum {
case Enum1:
case Enum2:
}
const Enum4 Enum = 42
// Expected: missing Enum3.
// Got: missing Enum3, Enum4.
// In this case, Enum4 doesn't exist in scope of switch statement.
}Additional context
No response
Supporter
- I am a sponsor through GitHub or OpenCollective
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested