-
Notifications
You must be signed in to change notification settings - Fork 466
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
CA1861 reporting for inline arrays in constructors of static properties #7365
Comments
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsDescriptionWhen setting a property outside of a constructor in a static properties setup it will report CA1861, if the same array is set via a constructor the analyzer will not report. It's possible that when the array is set via a constructor parameter an optimization is made by the compiler that it can't make by setting the property "after" the constructor. Reproduction StepsThe following will report CA1861 on the array creation.
If the array is a constructor parameter it will not report like in the following
Expected behaviorAs this is a static property and the category is performance I believe it should not fire as it is only allocating the array once. Actual behaviorThe analyzer should not detect an issue Regression?No response Known WorkaroundsAdd the initialization to a constructor or invoke the auto refactor in VS to make a cosnt array. ConfigurationWindows 11 x64 on .Net 8 RC2 (8.0.0-rc.2.23479.6) Other informationNo response
|
Once this is approved, I'd be happy to attempt a fix |
@johnthcall this issue most likely belongs in dotnet/roslyn-analyzers |
@steveberdy If you're still interested in tackling this, I can assign it to you. |
@jeffhandley sure, I'll take it. |
Description
When setting a property outside of a constructor in a static properties setup it will report CA1861, if the same array is set via a constructor the analyzer will not report. It's possible that when the array is set via a constructor parameter an optimization is made by the compiler that it can't make by setting the property "after" the constructor.
Reproduction Steps
The following will report CA1861 on the array creation.
If the array is a constructor parameter it will not report like in the following
Expected behavior
As this is a static property and the category is performance I believe it should not fire as it is only allocating the array once.
Actual behavior
The analyzer should not detect an issue
Regression?
No response
Known Workarounds
Add the initialization to a constructor or invoke the auto refactor in VS to make a cosnt array.
Configuration
Windows 11 x64 on .Net 8 RC2 (8.0.0-rc.2.23479.6)
Other information
No response
The text was updated successfully, but these errors were encountered: