Skip to content

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

@jnm2

Description

@jnm2

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)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions