Skip to content

Conversation

@DoctorKrolic
Copy link
Contributor

Fixes: #40773

Matches behavior of syntax token in test above

@DoctorKrolic DoctorKrolic requested a review from a team as a code owner November 25, 2025 18:00
@dotnet-policy-service dotnet-policy-service bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Nov 25, 2025
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Seems to match SyntaxToken now.

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Seems to match SyntaxToken now.

@DoctorKrolic
Copy link
Contributor Author

Can I have a review here please?!

{
// https://github.com/dotnet/roslyn/issues/40773
return this.SyntaxTree!.GetDiagnostics(this);
return this.SyntaxTree?.GetDiagnostics(this) ?? SpecializedCollections.EmptyEnumerable<Diagnostic>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SpecializedCollections.EmptyEnumerable()

Matches behavior of syntax token

Looking at implementation for SyntaxToken, it looks like it might return non-empty result even when SyntaxTree is null.

@AlekseyTs
Copy link
Contributor

@DoctorKrolic

Fix null refs of freshly constructed syntax trivia

Consider making the title more detailed. For example by mentioning what APIs are getting fixed/changed

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 1)

@DoctorKrolic DoctorKrolic changed the title Fix null refs of freshly constructed syntax trivia Fix null refs when calling GetLocation() or GetDiagnostics() of freshly constructed syntax trivia Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SyntaxTrivia doesn't properly validate it's SyntaxTree

3 participants