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

[MemberNotNull] isn't respected on local functions #56256

Closed
stephentoub opened this issue Sep 8, 2021 · 5 comments · Fixed by #75448 · May be fixed by #63310
Closed

[MemberNotNull] isn't respected on local functions #56256

stephentoub opened this issue Sep 8, 2021 · 5 comments · Fixed by #75448 · May be fixed by #63310
Assignees
Labels
Area-Compilers Bug New Language Feature - Nullable Reference Types Nullable Reference Types Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@stephentoub
Copy link
Member

Version Used:
9525fa5

Steps to Reproduce:
https://sharplab.io/#v2:EYLgtghglgdgPgYhgVwDaosVBTABNmTHAWACgABABl3IEYA6AESggHMYB7AZwBcoBjLvQDCHACbYAgoVQBPLlC4BuMmXIBmGgCZcwsgG8yuY7gAOAJygA3CDzwdgAK2z8eAflwB9B45WkTuEYmGriwPLgAsgAUAJRBxob+ASYAkjBQPLF+ycEA7F4+9ADi2DwAEhBcABaiElnxyQ0BANoR2GDA2OYAchw83WioUYRg2BwAZlHeTjExALpNwQAsuGkZsbgAvAB8BU5buDDYAO64Pi6ZMdkmAL5kN0A===

#nullable enable
using System.Diagnostics.CodeAnalysis;

public class C
{
    private object? _obj;
    
    public int M()
    {
        Init();
        return _obj.GetHashCode();
        
        [MemberNotNull(nameof(_obj))]
        void Init() => _obj = new object();
    }
}

Expected Behavior:
No warning.

Actual Behavior:
warning CS8602: Dereference of a possibly null reference.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Sep 8, 2021
@stephentoub
Copy link
Member Author

Ah, dup of #47896

@stephentoub
Copy link
Member Author

Apparently I opened the same issue last year ;-)
#49234

@Youssef1313
Copy link
Member

@stephentoub #47896 was closed as fixed, but this issue still repros. This issue wasn't probably an exact dupe of #47896 and should be reopened. Can you reopen? Thanks!

@stephentoub stephentoub reopened this Nov 26, 2021
@jaredpar jaredpar added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 4, 2022
@jaredpar jaredpar added this to the 17.2 milestone Jan 4, 2022
@jcouv jcouv modified the milestones: 17.2, 17.3 Feb 16, 2022
@jaredpar jaredpar modified the milestones: 17.3, C# 12.0 Jun 29, 2022
@RikkiGibson
Copy link
Contributor

RikkiGibson commented Apr 10, 2023

LDM did decide on an internal thread that we should do this and that MemberNotNull applied to the function modifies the state of members of the captured this.

@jaredpar jaredpar modified the milestones: C# 12.0, Backlog Sep 12, 2023
@jcouv jcouv added the help wanted The issue is "up for grabs" - add a comment if you are interested in working on it label Dec 7, 2023
@jcouv jcouv added the 4 - In Review A fix for the issue is submitted for review. label Oct 9, 2024
@jcouv jcouv added Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented and removed 4 - In Review A fix for the issue is submitted for review. help wanted The issue is "up for grabs" - add a comment if you are interested in working on it labels Oct 31, 2024
@jcouv
Copy link
Member

jcouv commented Nov 12, 2024

Implemented in 17.13 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug New Language Feature - Nullable Reference Types Nullable Reference Types Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
Status: Done
5 participants