-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[Group 1] Enable nullable annotations for Microsoft.Extensions.Primitives
#57395
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
src/libraries/Microsoft.Extensions.Primitives/ref/Microsoft.Extensions.Primitives.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/ref/Microsoft.Extensions.Primitives.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/ref/Microsoft.Extensions.Primitives.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/ref/Microsoft.Extensions.Primitives.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/ref/Microsoft.Extensions.Primitives.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/ref/Microsoft.Extensions.Primitives.cs
Outdated
Show resolved
Hide resolved
public override bool Equals(object obj) { throw null; } | ||
public bool Equals(string text) { throw null; } | ||
public override bool Equals(object? obj) { throw null; } | ||
public bool Equals(string? text) { throw null; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this throw for null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, in implementation text
is non-nullable and everything compiles fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't allow me to make it non-nullable...
You need to change the type of the interface being implemented to IEquatable<string?>
.
in implementation text is non-nullable and everything compiles fine
Yes, because the code never tries to dereference a maybe-null value. The first thing the code does is check whether it's null and throw if it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I misread what you'd written. IEquatable<T>
is defined to expect Equals
always allows null (it accepts a T?
), which is why this is complaining about trying to specify a non-nullable value. I think the implementation should be changed to return false rather than throwing, and then typed as string?
, but I'll defer here to @dotnet/area-microsoft-extensions area owners.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made it return false.
Microsoft.Extensions.Primitives
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue DetailsRelated to #43605
|
src/libraries/Microsoft.Extensions.Primitives/src/StringTokenizer.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/src/CompositeChangeToken.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/src/StringSegment.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/src/ChangeToken.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/src/CompositeChangeToken.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/src/CompositeChangeToken.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/src/StringValues.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/src/StringValues.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/src/StringValues.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/tests/ChangeTokenTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Primitives/tests/StringSegmentTest.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you a lot for this contribution!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the contribution!
I think StringSegment needs another look, Buffer is allowed to be null so you can distinguish between string.Empty and a null string.
This is causing issues in AspNetCore when trying to consume the Runtime update because we expect to be able to pass null to StringSegment. dotnet/aspnetcore#35547 |
Oh, I see. Second constructor thrown me off (it throws if |
Shouldn't |
Related to #43605