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

Error thrown when using record struct. #263

Open
Gestalte opened this issue Dec 20, 2023 · 0 comments
Open

Error thrown when using record struct. #263

Gestalte opened this issue Dec 20, 2023 · 0 comments

Comments

@Gestalte
Copy link

I get the following error in the Error List after installing ErrorProne.NET. I believe this is because it can't parse the primary constructor syntax of record structs.

Severity	Code	Project	Description	File	Line	Suppression State
Warning	AD0001	BasketManagement	Analyzer 'ErrorProne.NET.StructAnalyzers.MakeStructReadOnlyAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.ParameterSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BasePropertyDeclarationSyntax'.'.
Exception occurred with following context:
Compilation: BasketManagement
ISymbol: ItemGroup (NamedType)

System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.ParameterSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BasePropertyDeclarationSyntax'.
   at ErrorProne.NET.Extensions.SyntaxNodeExtensions.<>c.<MarkedWithReadOnlyModifier>b__4_0(SyntaxReference p) in C:\Sources\GitHub\ErrorProne.NET\src\ErrorProne.NET.Core\SyntaxNodeExtensions.cs:line 50
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at ErrorProne.NET.Extensions.SyntaxNodeExtensions.MarkedWithReadOnlyModifier(IPropertySymbol property) in C:\Sources\GitHub\ErrorProne.NET\src\ErrorProne.NET.Core\SyntaxNodeExtensions.cs:line 48
   at ErrorProne.NET.StructAnalyzers.ReadOnlyAnalyzer.IsReadonly(ISymbol member) in C:\Sources\GitHub\ErrorProne.NET\src\ErrorProne.NET.StructAnalyzers\ReadOnlyAnalyzer.cs:line 61
   at ErrorProne.NET.StructAnalyzers.ReadOnlyAnalyzer.<>c__DisplayClass1_0.<StructCanBeReadOnly>b__4(<>f__AnonymousType0`2 m) in C:\Sources\GitHub\ErrorProne.NET\src\ErrorProne.NET.StructAnalyzers\ReadOnlyAnalyzer.cs:line 48
   at System.Linq.Enumerable.All[TSource](IEnumerable`1 source, Func`2 predicate)
   at ErrorProne.NET.StructAnalyzers.ReadOnlyAnalyzer.StructCanBeReadOnly(INamedTypeSymbol namedTypeSymbol, SemanticModel semanticModel) in C:\Sources\GitHub\ErrorProne.NET\src\ErrorProne.NET.StructAnalyzers\ReadOnlyAnalyzer.cs:line 48
   at ErrorProne.NET.StructAnalyzers.MakeStructReadOnlyAnalyzer.AnalyzeStructDeclaration(SymbolAnalysisContext context) in C:\Sources\GitHub\ErrorProne.NET\src\ErrorProne.NET.StructAnalyzers\MakeStructReadOnlyAnalyzer.cs:line 45
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)

The record struct in question is defined like this:

public sealed record struct ItemGroup(int Amount, PlatonicItem Item);

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