Skip to content

Commit

Permalink
Update all places that dereference SyntaxTrivia.SyntaxTree to make su…
Browse files Browse the repository at this point in the history
…re it can't be null

#2354
  • Loading branch information
bjornhellander committed Dec 3, 2023
1 parent 349ec90 commit 145b958
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static void HandleWhitespaceTrivia(SyntaxTreeAnalysisContext context, Sy
return;
}

if (trivia.SyntaxTree.GetMappedLineSpan(trivia.Span).StartLinePosition.Character == 0)
if (trivia.SyntaxTree == null || trivia.SyntaxTree.GetMappedLineSpan(trivia.Span).StartLinePosition.Character == 0)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static void HandleSyntaxTree(SyntaxTreeAnalysisContext context)
previousTrivia = trivia;
}

if (previousTrivia.IsKind(SyntaxKind.WhitespaceTrivia) && previousTrivia.Span.End == previousTrivia.SyntaxTree.Length)
if (previousTrivia.IsKind(SyntaxKind.WhitespaceTrivia) && previousTrivia.Span.End == previousTrivia.SyntaxTree?.Length)
{
// Report whitespace at the end of the last line in the document
context.ReportDiagnostic(Diagnostic.Create(Descriptor, previousTrivia.GetLocation()));
Expand Down

0 comments on commit 145b958

Please sign in to comment.