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

#nullable enable should detect nested initialization of fields #35592

Closed
mengluwang121 opened this issue May 8, 2019 · 2 comments
Closed

#nullable enable should detect nested initialization of fields #35592

mengluwang121 opened this issue May 8, 2019 · 2 comments
Labels
Area-Compilers Feature - Nullable Reference Types Nullable Reference Types Resolution-Duplicate The described behavior is tracked in another issue

Comments

@mengluwang121
Copy link

mengluwang121 commented May 8, 2019

Version Used:
C# 8.0, .Net Core SDK 2.1.700

Steps to Reproduce:
With #nullable enable, "Non-nullable field is uninitialized" warning will show up if some field is not initialized in constructor. But sometimes we want to initialize some thing in a function so that it can be well structured, or we need to call an abstract function on children class. So this is bug is filed as a suggestion to consider detect nested initialization for #nullable enable. Thank you so much!
Code example:

 public PipeProgressEventArgs(Stream stream)​
            : base(stream)​
        {​
            Initialize();​
        }​
​
        private void Initialize()​
        {​
            Progress = new ProgressEventArgs("Package", 12, ProgressType.Install);​
        }​

Expected Behavior:
No warning.
Actual Behavior:
"Non-nullable field is uninitialized" shows up around the constructor.

@jcouv
Copy link
Member

jcouv commented May 9, 2019

@mengluwang121 Yes, we recognize there is a pain point around this warning as many initialization patterns exist and the compiler currently produces warnings when it fails to understand them. We're looking to refine this.

@jaredpar
Copy link
Member

Dupe of #32358

@jaredpar jaredpar added the Resolution-Duplicate The described behavior is tracked in another issue label May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Nullable Reference Types Nullable Reference Types Resolution-Duplicate The described behavior is tracked in another issue
Projects
None yet
Development

No branches or pull requests

3 participants