Skip to content
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

CA2009 crashes on new int[0].ToImmutableArray() (.NET 8 Preview 1) #6501

Closed
alexrp opened this issue Feb 22, 2023 · 2 comments
Closed

CA2009 crashes on new int[0].ToImmutableArray() (.NET 8 Preview 1) #6501

alexrp opened this issue Feb 22, 2023 · 2 comments

Comments

@alexrp
Copy link
Contributor

alexrp commented Feb 22, 2023

Analyzer

Diagnostic ID: CA2009: Do not call ToImmutableCollection on an ImmutableCollection value

Analyzer source

SDK: Built-in CA analyzers in .NET 5 SDK or later

Version: SDK 8.0.100-preview.1.23115.2

Describe the bug

CA2009 is crashing when calling ToImmutableArray() on an array creation expression.

Steps To Reproduce

$ cat tests.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <AnalysisLevel>latest-all</AnalysisLevel>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>
$ cat Program.cs
using System.Collections.Immutable;

var values = new int[0].ToImmutableArray();

Expected behavior

No exception.

Actual behavior

CSC : warning AD0001: Analyzer 'Microsoft.NetCore.Analyzers.ImmutableCollections.DoNotCallToImmutableCollectionOnAnImmutableCollectionValue Analyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.ArrayTypeSymbol' to type 'Microsoft.CodeAnalysis.INamedTypeSymbol'.'.

@alexrp
Copy link
Contributor Author

alexrp commented Mar 17, 2023

@Evangelink can this be closed as of #6476?

@alexrp
Copy link
Contributor Author

alexrp commented Jan 12, 2024

Seems to be fixed.

@alexrp alexrp closed this as completed Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant