Improve asymmetries in binary patterns #8888
Unanswered
jcouv
asked this question in
Language Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Binary patterns currently suffer from some asymmetries due to the rules for flowing types. Here's an example:
Since the last case in each set is valid, the first two cases should be valid too.
Adding an
object or
should let the input type flow to the pattern after theor
.Adding an
not string or
should let thestring
type flow to the pattern after theor
.I'm not sure precisely what the rules should be. We'd have to decide what type should flow from multiple
not Type
patterns:My intuition is that we could track a "negated narrowed type" and flow it through:
Type
pattern has narrowed type which is the least specific betweenType
and input type (sostring
wins betweenstring
andobject
)not Type
pattern has narrowed type input type and "negated narrowed type"Type
leftPattern or rightPattern
pattern would flow the "negated narrowed type" from the left pattern and use that as the input type for the right patternFYI @AlekseyTs @MadsTorgersen
Relates to work on redundant patterns: dotnet/roslyn#75581
Beta Was this translation helpful? Give feedback.
All reactions