Skip to content

Roslyn fails to take into account lifted operators' behavior resulting in false postivie nulalbility warnings #61361

@TessenR

Description

@TessenR

Version Used:

Branch main (11 May 2022)
Latest commit [e6b5dd8](https://github.com/dotnet/roslyn/commit/e6b5dd830f1b790bd80e62272129cc040d0a2fdc) by Manish Vasani:
Merge pull request #61105 from mavasani/FixAllRawString

Add FixAll support for "Convert to raw string" refactoring

Steps to Reproduce:

using System;

#nullable enable
class C
{
  public static DateTime Test(DateTime? first, DateTime? second, DateTime? third)
  {
    if (first < third)
    {
      if (second < first.Value) // CS8629: Nullable value type may be null.
      {

      }
    }

    return DateTime.Now;
  }
}

Expected Behavior:
No warnings. A lifted operator is used and it's known to return false if one or both of its operands are null according to the language specification. Therefore, if the operator returned true both operands are not nulalble.

Actual Behavior:
False positive CS8629: Nullable value type may be null warning is reported for first.Value

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions