This specification does not describe target-typed switch expressions. See
dotnet/csharplang#2389
https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/patterns.md
The type of the switch_expression is the best common type (§12.6.3.15) of the expressions appearing to the right of the => tokens of the switch_expression_arms if such a type exists and the expression in every arm of the switch expression can be implicitly converted to that type. In addition, we add a new switch expression conversion, which is a predefined implicit conversion from a switch expression to every type T for which there exists an implicit conversion from each arm's expression to T.
We have to be careful defining when the common type must exist (when there is no target type) and when it doesn't (the switch is target-typed). The spec must say that when there is no target type, it is an error if there is no common type.
Originally posted by @gafter in #873 (comment)
This specification does not describe target-typed switch expressions. See
dotnet/csharplang#2389
https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/patterns.md
The type of the switch_expression is the best common type (§12.6.3.15) of the expressions appearing to the right of the => tokens of the switch_expression_arms if such a type exists and the expression in every arm of the switch expression can be implicitly converted to that type. In addition, we add a new switch expression conversion, which is a predefined implicit conversion from a switch expression to every type T for which there exists an implicit conversion from each arm's expression to T.
We have to be careful defining when the common type must exist (when there is no target type) and when it doesn't (the switch is target-typed). The spec must say that when there is no target type, it is an error if there is no common type.
Originally posted by @gafter in #873 (comment)