dotnet/roslyn

Nullable check ignores NotNullIfNotNullAttribute when the argument is method group

Open

#77.475 aberto em 9 de mar. de 2025

Ver no GitHub
 (5 comments) (0 reactions) (0 assignees)C# (4.257 forks)batch import
Area-CompilersBugFeature - Nullable Reference Typeshelp wanted

Métricas do repositório

Stars
 (20.414 stars)
Métricas de merge de PR
 (Mesclagem média 6d 17h) (256 fundiu PRs em 30d)

Description

.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

Guia do colaborador