-
Notifications
You must be signed in to change notification settings - Fork 468
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
Conversation
@@ -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() |
There was a problem hiding this comment.
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 && |
There was a problem hiding this comment.
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.
src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Runtime/AvoidConstArraysTests.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Runtime/AvoidConstArrays.cs
Outdated
Show resolved
Hide resolved
Codecov Report
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 <[email protected]>
Fixes #6686