-
-
Couldn't load subscription status.
- Fork 412
Open
Labels
rule requestAdding a new ruleAdding a new rule
Description
Rule request
Thesis
We should support simplifying match statements with only one case and no wildcard:
Example:
match x:
case 1:
do_something()Can be rewritten as:
if x == 1:
do_something()Reasoning
Even without an else branch, a single-case match is unnecessarily complex compared to a simple if. The intent is clear, and using if reduces nesting and cognitive load.
This is especially common in validation or dispatch logic where only one condition matters.
When should this be allowed?
Only when:
- There is exactly one case
- The pattern is simple (literal, constant, enum, etc.)
- No guard (
if...) is used
Originally posted by @sobolevn in #3526 (review)
sobolevn
Metadata
Metadata
Assignees
Labels
rule requestAdding a new ruleAdding a new rule