Replies: 7 comments 1 reply
-
i = b ? ref x : ref throw null; I don't think this syntax makes sense, there is no reference to anything in the else expression, so there shouldn't be a |
Beta Was this translation helpful? Give feedback.
-
I like the case where We do not require public ref readonly C M2() => throw null; |
Beta Was this translation helpful? Give feedback.
-
I'm with @svick here in thinking that |
Beta Was this translation helpful? Give feedback.
-
This appears to be a bug in Roslyn's implementation of C# 7.2. Is there a reason it's filed here? While conditional-ref.md doesn't call out this case specifically, the throw-expression.md document is clear about the behavior:
Even if |
Beta Was this translation helpful? Give feedback.
-
Not technically a bug. There are very few places where throw expression is allowed - cant assign or pass as a method argument for example, ref or not. It seems everyone agrees that ref ternary should allow it. |
Beta Was this translation helpful? Give feedback.
-
True, but the syntax in question is one of the three places where it is explicitly allowed. |
Beta Was this translation helpful? Give feedback.
-
The 2nd example currently produces |
Beta Was this translation helpful? Give feedback.
-
i = b ? ref x : throw null;
gives a surprisingerror CS8402: Both conditional operator values must be ref values or neither may be a ref value
This is disallowed in 7.2 (which introduces ref ternaries), but maybe it should be allowed later on (it seems irregular not to allow).
Should the syntax be:
i = b ? ref x : throw null;
, ori = b ? ref x : ref throw null;
?FYI @VSadov @gafter
Beta Was this translation helpful? Give feedback.
All reactions