Replies: 2 comments 2 replies
-
The line if (b is Derived2 d) ; would compile fine however, so not all pattern matching is broken, just in |
Beta Was this translation helpful? Give feedback.
-
This seems to be intended behavior according to section 13.8.3 of the spec:
So if the type of the expression inside the switch statement is implicitly convertible to exactly one of those types, then the overall type of the switch statement will always be that converted type, causing type pattern matches to fail. This also means if you define more than one of those implicit conversions (such as also adding an You could imagine it falling back to using the directly given type if treating it as the converted type fails, but I assume it's undesirable for specific cases to be able to impact the overall governing type of the switch statement. I also can't speak to why exactly it automatically converts the type like this to begin with. |
Beta Was this translation helpful? Give feedback.
-
When you uncomment the implicit operator, the compiler fails on the
switch case Derived*
pattern matching lines, stating that b is an expression of type 'long'This seems wrong to me.
Tested with LangVersion latest, up-to-date VS
Beta Was this translation helpful? Give feedback.
All reactions