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

AD0001 when invoking function pointer #547

Open
trympet opened this issue Dec 4, 2023 · 0 comments
Open

AD0001 when invoking function pointer #547

trympet opened this issue Dec 4, 2023 · 0 comments

Comments

@trympet
Copy link

trympet commented Dec 4, 2023

Hi @JohanLarsson, I'm hitting AD0001 for the following snippet with version 4.0.7:

namespace AnalyzerRepro;

internal class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");
    }
}

unsafe class Repro
{
    public void Error() => ((delegate* unmanaged<void>)null)();
}

with the error

Severity	Code	Description	Project	File	Line	Suppression State	Details
Warning	AD0001	Analyzer 'IDisposableAnalyzers.DisposeCallAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.FunctionPointerTypeSymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.'.
Exception occurred with following context:
Compilation: AnalyzerRepro
SyntaxTree: D:\source\test\AnalyzerRepro\AnalyzerRepro\Program.cs
SyntaxNode: ((delegate* unmanaged<void>)null ... [InvocationExpressionSyntax]@[206..241) (12,27)-(12,62)

System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.FunctionPointerTypeSymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.
   at Gu.Roslyn.AnalyzerExtensions.SemanticModelExt.GetSymbolSafe(SemanticModel semanticModel, InvocationExpressionSyntax node, CancellationToken cancellationToken)
   at Gu.Roslyn.AnalyzerExtensions.SemanticModelExt.TryGetSymbol(SemanticModel semanticModel, InvocationExpressionSyntax node, CancellationToken cancellationToken, IMethodSymbol& symbol)
   at Gu.Roslyn.AnalyzerExtensions.InvocationExpressionSyntaxExt.IsSymbol(InvocationExpressionSyntax candidate, QualifiedMethod symbol, SemanticModel semanticModel, CancellationToken cancellationToken)
   at IDisposableAnalyzers.DisposeCall.MatchDispose(InvocationExpressionSyntax candidate, SemanticModel semanticModel, CancellationToken cancellationToken)
   at IDisposableAnalyzers.DisposeCallAnalyzer.Handle(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: IDISP007, IDISP016, IDISP017	AnalyzerRepro	D:\source\test\AnalyzerRepro\AnalyzerRepro\AnalyzerRepro.csproj	1	Active	

Possibly relevant: #308

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