dotnet/roslyn

Nullable check ignores NotNullIfNotNullAttribute when the argument is method group

開放

#77,475 建立於 2025年3月9日

 (5 則留言) (0 個反應) (0 位負責人)C# (4,257 個分叉)batch import
Area-CompilersBugFeature - Nullable Reference Typeshelp wanted

倉庫指標

星標
 (20,414 顆星)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 256 個 PR)

描述

.NET SDK 9.0.200:

Steps to Reproduce:

#nullable enable
using System.Linq; // Enumerable.Select

string[] a = ["1", "a"]; // element not null

_ = a.Select(Foo) // returns string?[]
    .First().ToString(); // CS8602, unexpected

_ = a.Select(t => Foo(t)) // returns string[]
    .First().ToString(); // correct, expected

[return: NotNullIfNotNull(nameof(x))]
string? Foo(string? x) => x;

Diagnostic Id:

CS8602

Expected Behavior:

Nullable check Does not ignore NotNullIfNotNullAttribute when the argument is method group

Actual Behavior:

Nullable check ignores NotNullIfNotNullAttribute when the argument is method group

貢獻者指南