dotnet/roslyn
在 GitHub 查看Nullable check ignores NotNullIfNotNullAttribute when the argument is method group
Open
#77,475 创建于 2025年3月9日
Area-CompilersBugFeature - Nullable Reference Typeshelp wanted
仓库指标
- Star
- (20,414 star)
- 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