Skip to content

AD0001 when invoking function pointer #547

Open
@trympet

Description

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions