-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Proposal: Disallow e is null and other constant patterns #15539
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
Comments
|
Currently all constant patterns generate that call. It's just not optimized yet. See #13247. |
Thanks, nice catch. |
Closing per #8409 (comment) as it's the intended usage and probably #8409 would be a non-issue. |
I think I closed this prematurely, because still I couldn't think of any good reason to permit constant patterns directly in top level |
@MadsTorgersen I propose we discuss this (disallowing constant patterns on the right of the @alrz |
Agreed 100%. To me this not only seems like unnecessary complexity, confusion for beginners, more inconsistency and ways to do essentially the same thing, but also like abuse of the is operator which has always meant instanceof in C#, and never any kind of comparison. |
The LDM discussed this yesterday and concluded that we intend to support constant patterns in the |
Uh oh!
There was an error while loading. Please reload this page.
e is null
is a good way for reference null check instead of(object)e == null
but it does not work with non-constant expressions e.g.e1 is e2
. I think multiple ways of doing the same thing would be (1) confusing for beginners and (2) it would cause yet another inconsistency all over the code base i.e. there should be a code style option to prefer one over the other. I'd rather have a dedicated operator for such operations (#8409) to cover all cases and maintain a consistent behavior instead of an operator that does not cover all cases and essentially is useful in comparing by value scenarios i.e. patterns.If it's here to stay I'd like to hear the rational behind it.
The text was updated successfully, but these errors were encountered: