Reporter | Manuel Pallier (manuel.pallier) |
---|---|
Created | Apr 24, 2018 4:39:09 PM |
Updated | Apr 24, 2018 4:54:24 PM |
Subsystem | Code Analysis - C# |
Assignee | Andrey Dyatlov (Andrey.Dyatlov) |
Priority | Normal |
State | Fixed In Branch |
Type | Bug |
Fix version | No Fix versions |
Affected versions | 2018.1 |
Fixed In Version ReSharper | Undefined |
VsVersion | All Versions |
Some inspections and quick fixes should be suppressed in expression trees because they produce code that contains compile errors.
Example:
// Query<T>() returns an IQueryable<T>
// Original
// Works, but shows inspection "Type check and casts can be merged"
var query = Query<Person>()
.Where(x => x is Customer && ((Customer)x).IsActive)
.ToList();
// After quick fix "Use pattern matching"
// Compile error: CS8122: An expression tree may not contain an 'is' pattern-matching operator.
var query1 = Query<Person>()
.Where(x => x is Customer customer && customer.IsActive)
.ToList();
// After quick fix "Use 'as' and check for null"
// Compile error: CS0834: A lambda expression with a statement body cannot be converted to an expression tree
var query2 = Query<Person>()
.Where(x =>
{
var customer = x as Customer;
return customer != null && customer.IsActive;
})
.ToList();
Maybe there are more cases, but this is what I found today.