CA2009 should not be raised when changing the generic type #7374
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers
False_Positive
A diagnostic is reported for non-problematic case
Analyzer
Diagnostic ID: CA2009:
Do not call ToImmutableCollection on an ImmutableCollection value
Analyzer source
NuGet Package: Microsoft.CodeAnalysis.NetAnalyzers
Version: 8.0.0
Describe the bug
CA2009 should not be raised when changing the generic type, i.e.
ImmutableList<T1>.ToImmutableList<T2>()
should be valid.Steps To Reproduce
Expected behavior
CA2009 should only trigger if the generic types are identical.
Actual behavior
CA2009 triggers even if the generic type is different.
Additional context
This is relevant when passing immutable collections to APIs that you do not control (obviously if I were creating
list2
to pass in to a method takingIReadOnlyList<IFoo>
, passinglist1
directly would be fine).The text was updated successfully, but these errors were encountered: