Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RikkiGibson opened this issue Sep 21, 2020 · 1 comment · Fixed by #56590
Closed

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

RikkiGibson opened this issue Sep 21, 2020 · 1 comment · Fixed by #56590
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug Feature - Nullable Reference Types Nullable Reference Types
Milestone

Comments

@RikkiGibson
Copy link
Contributor

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)

@jcouv
Copy link
Member

jcouv commented Sep 28, 2021

Resolved in 17.0p5

@jcouv jcouv closed this as completed Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug Feature - Nullable Reference Types Nullable Reference Types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants