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

Handle null initializer for array creation operation #6696

Merged
merged 2 commits into from
Jun 19, 2023

Conversation

mavasani
Copy link
Contributor

Fixes #6686

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

@Youssef1313

@@ -804,5 +804,30 @@ private void M(string eventName, string msg)
LanguageVersion = LanguageVersion.CSharp8
}.RunAsync();
}

[Fact, WorkItem(6686, "https://github.com/dotnet/roslyn-analyzers/issues/6686")]
public Task ArrayWithoutInitializer_Diagnostic()
Copy link
Contributor 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

@@ -103,7 +103,8 @@ public override void Initialize(AnalysisContext context)
}

// Must be literal array
if (arrayCreationOperation.Initializer.ElementValues.Any(x => x is not ILiteralOperation))
if (arrayCreationOperation.Initializer != null &&
Copy link
Contributor 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.

Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

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

LGTM

@codecov
Copy link

codecov bot commented Jun 19, 2023

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     

@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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NullReferenceException from CA1861
2 participants