-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Fix warnings found with CA1861 Avoid constant arrays as arguments #86229
Conversation
Tagging subscribers to this area: @dotnet/area-meta Issue DetailsEnable new analyzer CA1861: Avoid constant arrays as arguments. And fix warnings found in runtime.
|
This is a potential deoptimization if the call is rarely made, right? |
...raries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/IDispatchMetaObject.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/VariantArray.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ExpressionBinder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Requests/src/System/Net/FtpControlStream.cs
Outdated
Show resolved
Hide resolved
src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs
Outdated
Show resolved
Hide resolved
...raries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/IDispatchMetaObject.cs
Show resolved
Hide resolved
Mono parts look fine |
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs
Outdated
Show resolved
Hide resolved
I see that the analyzer has auto-fixer. Is the auto-fixer smart enough to skip cases where the array is mutated later? I am just wondering about potential correctness problems introduced by the auto-fixer. |
It only flag literal arrays and suggest a fixer |
src/libraries/System.Net.Requests/src/System/Net/FtpControlStream.cs
Outdated
Show resolved
Hide resolved
/azp run runtime-wasm |
Azure Pipelines successfully started running 1 pipeline(s). |
I believe Jan is expressing concern about a case like this: char[] array = new char[] { 'a', 'b', 'c' };
array[0] = Read();
Use(array); Will the analyzer flag that and auto-fix it to: private static readonly char[] s_cached = new char[] { 'a', 'b', 'c' };
...
char[] array = s_cached;
array[0] = Read();
Use(array); ? If it would, that's obviously not safe. |
I believe now there is no any blocker or open question/comment for this PR, please finish the review @danmoseley @jkotas @kg @stephentoub, thank you! |
src/libraries/System.Text.RegularExpressions/gen/UpgradeToGeneratedRegexCodeFixer.cs
Show resolved
Hide resolved
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs
Outdated
Show resolved
Hide resolved
…XmlSerializationILGen.cs
Failures unrelated and looks all known including #86919 |
Enable new analyzer CA1861: Avoid constant arrays as arguments. And fix warnings found in runtime.