[Group 1] Enable nullable annotations for Microsoft.Extensions.Primitives#57395
[Group 1] Enable nullable annotations for Microsoft.Extensions.Primitives#57395eerhardt merged 21 commits intodotnet:mainfrom
Microsoft.Extensions.Primitives#57395Conversation
|
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.
Doesn't this throw for null?
There was a problem hiding this comment.
Interestingly, in implementation text is non-nullable and everything compiles fine
There was a problem hiding this comment.
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.
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.
Made it return false.
Microsoft.Extensions.Primitives
|
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue DetailsRelated to #43605
|
src/libraries/Microsoft.Extensions.Primitives/src/CompositeChangeToken.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/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
krwq
left a comment
There was a problem hiding this comment.
LGTM, thank you a lot for this contribution!
eerhardt
left a comment
There was a problem hiding this comment.
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