Replies: 1 comment
-
Given that your property pattern block doesn't apply to the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
While I was playing with the new list patterns in C# 11, I noticed an inconsistency of sorts with the type pattern.
Assuming top-level statements in a console application, if I write this:
...then I only get a compile-time error on the pattern in
typePattern
, becauseFlag
doesn't exist inMyClass
. Type matching first limits the property matching to the matched type. The pattern intypePatternReversed
however basically ignores the type part - because the property pattern infers theMySubClass
type, which inherits fromMyClass
, the type check seems to always be true.For completeness, if I negate the type patterns:
...then I get two compile-time errors as those patterns cannot be matched.
For the sake of consistency I would expect the type pattern to always limit the property pattern type regardless of order.
Beta Was this translation helpful? Give feedback.
All reactions