Skip to content
This repository was archived by the owner on Nov 12, 2026. It is now read-only.

Handle null initializer for array creation operation - #6696

Merged
mavasani merged 2 commits into
dotnet:mainfrom
mavasani:Issue6686
Jun 19, 2023
Merged

mavasani merged 2 commits into
dotnet:mainfrom
mavasani:Issue6686

Conversation

@mavasani

Copy link
Copy Markdown

Fixes #6686

@mavasani
mavasani requested a review from a team as a code owner June 19, 2023 10:53
@mavasani

Copy link
Copy Markdown
Author

@Youssef1313

}

[Fact, WorkItem(6686, "https://github.com/dotnet/roslyn-analyzers/issues/6686")]
public Task ArrayWithoutInitializer_Diagnostic()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified AD0001 from this test prior to the fix


// Must be literal array
if (arrayCreationOperation.Initializer.ElementValues.Any(x => x is not ILiteralOperation))
if (arrayCreationOperation.Initializer != null &&

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: I am working on moving the Microsoft.CodeAnalysis package reference for NetAnalyzers project from 3.3.1 to 3.11, which should bring in the nullable annotated IOperation API surface and hence prevent such NREs in future.

@Youssef1313 Youssef1313 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@codecov

codecov Bot commented Jun 19, 2023 •

Copy link
Copy Markdown

Codecov Report

Merging #6696 (1a70e89) into main (6e440ef) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6696   +/-   ##
=======================================
  Coverage   96.39%   96.39%           
=======================================
  Files        1379     1379           
  Lines      322416   322439   +23     
  Branches    10461    10461           
=======================================
+ Hits       310782   310811   +29     
+ Misses       9140     9135    -5     
+ Partials     2494     2493    -1     

…dConstArrays.cs

Co-authored-by: Youssef Victor <youssefvictor00@gmail.com>
@mavasani
mavasani merged commit ebd3126 into dotnet:main Jun 19, 2023
@mavasani
mavasani deleted the Issue6686 branch June 19, 2023 12:12
@github-actions github-actions Bot added this to the vNext milestone Jun 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullReferenceException from CA1861

2 participants