Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some AssumeNotNull assumptions #10901

Merged
merged 4 commits into from
Sep 19, 2024
Merged

Conversation

davidwengier
Copy link
Contributor

Fixes most of the hits on https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2223687 in 17.12 P2 and above

@davidwengier davidwengier requested a review from a team as a code owner September 19, 2024 02:08
@davidwengier davidwengier changed the title Allow TextChange.NewText to be null Fix some AssumeNotNull assumptions Sep 19, 2024
@@ -30,6 +29,5 @@ public static TextChange GetTextChange(this SourceText text, TextEdit edit)
=> new(text.GetTextSpan(edit.Range), edit.NewText);

public static TextEdit GetTextEdit(this SourceText text, TextChange change)
=> RoslynLspFactory.CreateTextEdit(text.GetRange(change.Span), change.NewText.AssumeNotNull());

=> RoslynLspFactory.CreateTextEdit(text.GetRange(change.Span), change.NewText ?? "");
Copy link
Contributor

Choose a reason for hiding this comment

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

""

Nit: string.Empty? not sure if it makes any difference...

Copy link
Member

Choose a reason for hiding this comment

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

IIRC, it does make a difference, but an absurdly small one. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it didn't make a difference after .NET Framework 2.0 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

No, it definitely made a difference in .NET Framework 2.0. There was actually effort to inline string.Empty for empty string literals in the JIT more aggressively post .NET Framework 4.0. I know that because it caused a bug that @jasonmalinowski and I ran into where the value of string.Empty could become corrupted by the COM marshaller if strings were annotated incorrectly (e.g. BStr instead of LPWStr).

Crazy days.

Copy link
Contributor

@alexgav alexgav left a comment

Choose a reason for hiding this comment

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

:shipit:

@davidwengier
Copy link
Contributor Author

Merging a PR from a plane... for the memes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants