Skip to content

Local functions don't report warnings for NotNull/NotNullWhen/NotNullIfNotNull #47896

@RikkiGibson

Description

@RikkiGibson

Version Used: d148f06

Steps to Reproduce:

#nullable enable
using System.Diagnostics.CodeAnalysis;

public class C
{
    public void M0(string? x)
    {
        local(ref x);
        
        void local([NotNull] ref string? x)
        {
            x = null;
        } // no warning, but one was expected
    }
    
    void M1([NotNull] ref string? x)
    {
        x = null;
    } // warning CS8777: Parameter 'x' must have a non-null value when exiting.
}

Expected Behavior: Warnings on both member methods and local functions with [NotNull] parameters

Actual Behavior: No warning on local function

We need to call functions like enforceNotNull, enforceMemberNotNull etc. here:

foreach (PendingBranch pending in pendingReturns)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions