-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Permit variable declaration under "or patterns". #3740
Comments
I'd like the ability to declare variables on either side of return value is TInner inner || innerConverter.ConvertFrom(context, culture, value) is TInner inner
? Wrap(inner)
: base.ConvertFrom(context, culture, value); |
((value as TInner) ?? (innerConverter.ConvertFrom(context, culture, value) as TInner)) is {} inner Well you do have an alternative, and I'd say they are both ugly syntax. |
I can't use |
4 tasks
Closing as championed at #4018 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
According to https://github.com/dotnet/csharplang/blob/6901635c383801e4d177085587aaccadaa7b2f11/proposals/patterns3.md#variable-definitions-and-definite-assignment, we will not be able to declare pattern variables under "or patterns".
Obviously this should be supported. We should at least allow cases where all branches of the "or pattern" declare the same number of variables of the same types. (For variables of different types, we should wait for #399.)
An example that this can simplify is
https://github.com/verybadcat/CSharpMath/blob/b8a5ab0ff9789627edf2f05927291a87631b29a0/CSharpMath.Evaluation/Evaluation.cs#L395-L403
The
when
clause can be simplified by #3435, but we still need to permit variable declaration under "or patterns" to merge the two cases into one and eliminate the unnecessarygoto
.The text was updated successfully, but these errors were encountered: