Open gafter opened 4 years ago
Here's another case:
public bool IsDefaultOrEmpty => _dictionary?.Count is null or 0;
Expected:
int? num = _dictionary?.Count;
return num.GetValueOrDefault() == 0;
Actual:
int? num = _dictionary?.Count;
return !num.HasValue || num.GetValueOrDefault() == 0;
See https://sharplab.io/#v2:EYLgZgpghgLgrgJwgZwLQAdYwggdsgZgB8ABARgDYACEgJhrIHYBYAKAG82ruaCHrgAe0EAbKgElkAQQDG8KCIAUAS1wwA/FQAeASioBeAHzaqy5FTIBuKlx4k+5AcLGSAolvQQ5EACYq1mroGxloG+haWbAC+bGxAA=
This issue is extracted from https://github.com/dotnet/roslyn/issues/31494
For source
The generated code is
The point is that we optimized
==
to avoid control-flow. We should do the same for the pattern-matching operations.