You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Version Used: '4.12.0-3.24523.4 (f3348c2)'. Language version: latest (13.0).
Steps to Reproduce:
int_value;intValue()=> _value;string?EnsureValid(intvalue)=>valueswitch{42=>thrownew System.Exception("Fatal"),>42=>"additional data"_ =>null}intNextValue()=>_value++;intPseudo(){varcurrent= Value();while(EnsureValid(current)is var result){if(result is"additional data")returncurrent;current= NextValue();}}intMinimized(){while(1is var number){}}intCompiles(){varcurrent= Value();while(true){varresult= EnsureValid(current);if(result is"additional data")returncurrent;current= NextValue();}}
Diagnostic Id: CS0161
Expected Behavior:
I expect this to compile as a while(true) {} would.
I couldn't come up with a particular reason for this to work differently from a true loop condition, there is no function call or other opaqueness to semantically cloud the equivalence with true, and the pattern always succeeds according to the language spec.
As for the code, you could argue the call and pattern belongs in the while body, however there are cases where doing something like this actually reads quite naturally. Certain coding patterns may rely on breaking out of the loop through another channel (exceptions in this case) and look fairly natural as part of the loop condition.
Actual Behavior:
error CS0161: 'Pseudo()': not all code paths return a value
error CS0161: 'Minimized()': not all code paths return a value
The text was updated successfully, but these errors were encountered:
I didn't believe the language ever thinks of patterns as constant values. But it's reasonable to say that it could for certain cases. I think that would be needed here so that it would know which points of the method are reachable or not.
So for this to happen, I think it would be necessary to change the language, which would happen at dotnet/csharplang.
If you started a discussion there, and tagged me, I'd be willing to bring this idea to the ldm to see what the team thinks about this.
Version Used: '4.12.0-3.24523.4 (f3348c2)'. Language version: latest (13.0).
Steps to Reproduce:
Diagnostic Id: CS0161
Expected Behavior:
I expect this to compile as a
while(true) {}
would.I couldn't come up with a particular reason for this to work differently from a
true
loop condition, there is no function call or other opaqueness to semantically cloud the equivalence withtrue
, and the pattern always succeeds according to the language spec.As for the code, you could argue the call and pattern belongs in the while body, however there are cases where doing something like this actually reads quite naturally. Certain coding patterns may rely on breaking out of the loop through another channel (exceptions in this case) and look fairly natural as part of the loop condition.
Actual Behavior:
The text was updated successfully, but these errors were encountered: