Analyzer to report arrays that can be converted to ImmutableArray<T> #5607
Labels
Area-Roslyn.Diagnostics.Analyzers
Community
Feature Request
help wanted
The issue is up-for-grabs, and can be claimed by commenting
Milestone
Brief description:
Find array fields who's contents are never mutated and suggest using an
ImmutableArray<T>
when possible. Intended for internal use in dotnet/roslyn.Languages applicable:
Both C# and Visual Basic.
Code example that the analyzer should report:
https://github.com/dotnet/roslyn/blob/b88948f10a1085980df7080f0b765b1a8c614436/src/Workspaces/Core/Portable/PatternMatching/PatternMatcher.cs#L27
The elements of this array are never mutated, and should never be mutated. It should be converted to an
ImmutableArray<char>
to enforce this invariant.Additional information:
See discussion on this PR for details. Not a duplicate of this issue, since it applies to arrays of all types. Also, because
ImmutableArray<T>
shares more apis withT[]
thanReadOnlySpan<T>
does and lacks the ref struct restrictions, we can report diagnostics more aggressively.If this gets accepted, I'm happy to implement the analyzer. I'm already working on a prototype, since @CyrusNajmabadi wants arrays converted to immutable arrays when possible.
The text was updated successfully, but these errors were encountered: