dotnet/roslyn

Lifted relational operators returning true should inform nullability tracking that neither operand can be null

开放

#56,517 创建于 2021年9月18日

 (1 条评论) (0 个反应) (0 位负责人)C# (4,257 个派生)batch import
Area-CompilersBugFeature - Nullable Reference Typeshelp wanted

仓库指标

星标
 (20,414 个星标)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

Version Used: 17.0.0-p4.0

These two CS8629 diagnostics should not be generated:

#nullable enable

using System;

class C
{
    void M(DateTime? a, DateTime? b)
    {
        if (a < b) // If this is true, neither variable can be null
        {
            // ⚠ CS8629 Nullable value type may be null.
            //  ↓
            _ = a.Value;
            //  ↓
            _ = b.Value;
        }
    }
}

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#lifted-operators:

For the relational operators < > <= >=, [...t]he lifted operator produces the value false if one or both operands are null.

贡献者指南