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

Exception thrown when directly accessing property off of a constructed object #7

Open
Emik03 opened this issue Sep 29, 2024 · 0 comments

Comments

@Emik03
Copy link

Emik03 commented Sep 29, 2024

The following ternary statement causes an exception to be thrown by this analyzer. You can find the surrounding context here.

HasSufficientMembers(raw)
    ? new Scaffolder(raw).Result
    : null;

Judging by the error, this should be enough information to fix the issue, but do let me know if you require me to create an MRE (Minimal Reproducible Example) otherwise:

CSC : warning AD0001: Analyzer 'Asyncify.VariableAccessAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.MethodSymbol' to type 'Microsoft.CodeAnalysis.ILocalSymbol'.'. [/home/emik/RiderProjects/Emik.SourceGenerators.Choices/Emik.SourceGenerators.Choices.csproj]
  Exception occurred with following context:
  Compilation: Emik.SourceGenerators.Choices
  SyntaxTree: /media/f/RiderProjects/Emik.SourceGenerators.Choices/Source/ExtendingGenerator.cs
  SyntaxNode: new Scaffolder(raw).Result [MemberAccessExpressionSyntax]@[3158..3184) (51,14)-(51,40)
  System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.MethodSymbol' to type 'Microsoft.CodeAnalysis.ILocalSymbol'.
  at Asyncify.VariableAccessChecker.FindSymbol(ExpressionSyntax expression)
  at Asyncify.VariableAccessChecker.ShouldUseTap(MemberAccessExpressionSyntax memberAccessExpression)
  at Asyncify.VariableAccessAnalyzer.CheckMemberAccess(SyntaxNodeAnalysisContext context)
  at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)
  -----
  Suppress the following diagnostics to disable this analyzer: AsyncifyVariable

Thanks for taking the time in reading my issue!

Emik03 added a commit to Emik03/Emik.Morsels that referenced this issue Sep 29, 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