Skip to content

NRE when analyzing discard pattern #17

@carlreinke

Description

@carlreinke

Analysis of

public class Test
{
    public void M(object o)
    {
        var s = o switch
        {
            int _ => "int",
            _ => "?",
        };
    }
}

results in

Analyzer 'NonCopyable.NonCopyableAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
Exception occurred with following context:
Compilation: NonCopyableAnalyzerTest
IOperation: DeclarationPattern
SyntaxTree: ...\Test.cs
SyntaxNode: int _ [DeclarationPatternSyntax]@[107..112) (6,12)-(6,17)

System.NullReferenceException: Object reference not set to an instance of an object.
   at NonCopyable.NonCopyableAnalyzer.<>c.<Initialize>b__16_8(OperationAnalysisContext oc)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteOperationAction>b__63_0(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----

Suppress the following diagnostics to disable this analyzer: NoCopy01, NoCopy02, NoCopy03, NoCopy04, NoCopy05, NoCopy06, NoCopy07, NoCopy08, NoCopy09, NoCopy10, NoCopy11, NoCopy12

Version: 0.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions