Skip to content
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

is null and is not null can't be used in expression contexts #3

Closed
jnm2 opened this issue Aug 24, 2021 · 3 comments · Fixed by #4
Closed

is null and is not null can't be used in expression contexts #3

jnm2 opened this issue Aug 24, 2021 · 3 comments · Fixed by #4
Assignees
Labels
bug Something isn't working

Comments

@jnm2
Copy link

jnm2 commented Aug 24, 2021

Looking at https://github.com/AArnott/CSharpIsNull/blob/main/src/CSharpIsNullAnalyzer/CSIsNull001.cs and https://github.com/AArnott/CSharpIsNull/blob/main/src/CSharpIsNullAnalyzer/CSIsNull002.cs, I didn't see anything checking for this.

using System;
using System.Linq.Expressions;

// ❌ CS8122 An expression tree may not contain an 'is' pattern-matching operator.
//                                        ↓↓↓↓↓↓↓↓↓
_ = (Expression<Func<string, bool>>)(s => s is null);

// ❌ CS8122 An expression tree may not contain an 'is' pattern-matching operator.
//                                        ↓↓↓↓↓↓↓↓↓↓↓↓↓
_ = (Expression<Func<string, bool>>)(s => s is not null);

_ = (Expression<Func<string, bool>>)(s => s is object); // Works

(SharpLab)

@jnm2
Copy link
Author

jnm2 commented Aug 24, 2021

This is what I settled on to deal with recursive nesting properly: dotnet/roslyn#51446 (reply in thread)

@AArnott AArnott added the help wanted Extra attention is needed label Aug 25, 2021
@AArnott
Copy link
Owner

AArnott commented Aug 25, 2021

Interesting. Do you have time to send a PR with tests and a fix?

@jnm2
Copy link
Author

jnm2 commented Aug 25, 2021

Sorry, probably not soon.

@AArnott AArnott self-assigned this Aug 28, 2021
@AArnott AArnott removed the help wanted Extra attention is needed label Aug 28, 2021
AArnott added a commit that referenced this issue Aug 28, 2021
These tests repro the cases called out in #3, plus a couple more.
AArnott added a commit that referenced this issue Sep 2, 2021
These tests repro the cases called out in #3, plus a couple more.
@AArnott AArnott closed this as completed in #4 Sep 3, 2021
@AArnott AArnott added the bug Something isn't working label Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants