ExhaustiveMatching icon indicating copy to clipboard operation
ExhaustiveMatching copied to clipboard

NullReferenceException in analyzer

Open WalkerCodeRanger opened this issue 4 years ago • 4 comments

System.NullReferenceException: Object reference not set to an instance of an object.
    at ExhaustiveMatching.Analyzer.TypeSymbolExtensions.GetFullName(ISymbol symbol)
    at ExhaustiveMatching.Analyzer.SwitchStatementAnalyzer.GetTypeSymbolMatched(SyntaxNodeAnalysisContext context, ITypeSymbol type, CasePatternSwitchLabelSyntax casePattern, HashSet`1 allCases, Boolean isClosed)
    at ExhaustiveMatching.Analyzer.SwitchStatementAnalyzer.<>c__DisplayClass3_0.<AnalyzeSwitchOnClosed>b__1(CasePatternSwitchLabelSyntax casePattern)
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
    at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
    at System.Collections.Immutable.DisposableEnumeratorAdapter`2.MoveNext()
    at System.Collections.Immutable.ImmutableHashSet`1.Union(IEnumerable`1 other, MutationInput origin)
    at System.Collections.Immutable.ImmutableHashSet`1.Union(IEnumerable`1 items, Boolean avoidWithComparer)
    at System.Collections.Immutable.ImmutableHashSet`1.Union(IEnumerable`1 other)
    at System.Collections.Immutable.ImmutableHashSet.ToImmutableHashSet[TSource](IEnumerable`1 source, IEqualityComparer`1 equalityComparer)
    at ExhaustiveMatching.Analyzer.SwitchStatementAnalyzer.AnalyzeSwitchOnClosed(SyntaxNodeAnalysisContext context, SwitchStatementSyntax switchStatement, ITypeSymbol type)
    at ExhaustiveMatching.Analyzer.SwitchStatementAnalyzer.Analyze(SyntaxNodeAnalysisContext context, SwitchStatementSyntax switchStatement)
    at ExhaustiveMatching.Analyzer.ExhaustiveMatchAnalyzer.AnalyzeSwitchStatement(SyntaxNodeAnalysisContext context)

WalkerCodeRanger avatar Oct 06 '19 05:10 WalkerCodeRanger

System.NullReferenceException: Object reference not set to an instance of an object.
    at ExhaustiveMatching.Analyzer.TypeSymbolExtensions.GetFullName(ISymbol symbol)
    at ExhaustiveMatching.Analyzer.SwitchStatementAnalyzer.GetTypeSymbolMatched(SyntaxNodeAnalysisContext context, ITypeSymbol type, CasePatternSwitchLabelSyntax casePattern, HashSet`1 allCases, Boolean isClosed)
    at ExhaustiveMatching.Analyzer.SwitchStatementAnalyzer.<>c__DisplayClass3_0.<AnalyzeSwitchOnClosed>b__1(CasePatternSwitchLabelSyntax casePattern)
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
    at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
    at System.Collections.Immutable.DisposableEnumeratorAdapter`2.MoveNext()
    at System.Collections.Immutable.ImmutableHashSet`1.Union(IEnumerable`1 other, MutationInput origin)
    at System.Collections.Immutable.ImmutableHashSet`1.Union(IEnumerable`1 items, Boolean avoidWithComparer)
    at System.Collections.Immutable.ImmutableHashSet`1.Union(IEnumerable`1 other)
    at System.Collections.Immutable.ImmutableHashSet.ToImmutableHashSet[TSource](IEnumerable`1 source, IEqualityComparer`1 equalityComparer)
    at ExhaustiveMatching.Analyzer.SwitchStatementAnalyzer.AnalyzeSwitchOnClosed(SyntaxNodeAnalysisContext context, SwitchStatementSyntax switchStatement, ITypeSymbol type)
    at ExhaustiveMatching.Analyzer.SwitchStatementAnalyzer.Analyze(SyntaxNodeAnalysisContext context, SwitchStatementSyntax switchStatement)
    at ExhaustiveMatching.Analyzer.ExhaustiveMatchAnalyzer.AnalyzeSwitchStatement(SyntaxNodeAnalysisContext context)

WalkerCodeRanger avatar Oct 19 '19 15:10 WalkerCodeRanger

Note: this GetFullName has moved to SymbolExtensions.GetFullName() and GetTypeSymbolMatched has moved to PatternAnalyzer.GetMatchedTypeSymbol()

WalkerCodeRanger avatar May 25 '20 22:05 WalkerCodeRanger

Do you have some code to reproduce this? I might have some time soon to attempt to look at it.

APIWT avatar Aug 04 '20 12:08 APIWT

Thanks for the offer to help!

No, unfortunately, I don't have code to reproduce this. That is a big part of why it isn't already fixed. I also haven't seen the error myself in a while. I believe it is caused by C# code that has other compile errors in it. I captured these stack traces from the Visual Studio error panel. I'd be editing code and then find that at some point one of these occurred. But then I'd close and reopen Visual Studio and it would go away. The code that caused it having been already edited out of existence by fixing other bugs. So, I think when the code is invalid, some invariant I'm thinking would always hold no longer holds, and thus something is null. But I don't know what and why.

WalkerCodeRanger avatar Aug 08 '20 14:08 WalkerCodeRanger