This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Fix some additional minor nullability issues #668
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These are a few minor nullability issues that don't seem to be caught by the C# compiler or Visual Studio, but Rider marks them as errors. They seem to be legitimate issues, so here are some fixes:
Tcould be a value type, in which case unboxing the potentially null result from?.Invokecould throw an exception. Usingdefaulthandles both value and reference types without errors.p.Nameis known to be not null here, butp.Name?.ToLowerInvariant()implies that it could be null, and should convert the type fromstringtostring?. But the value is used as a dictionary key which must be non-null.TResultmay be null, but it is not known to be either a value type or a reference type, so it's not possible to useTResult?. A[MaybeNullWhen(false)]out parameter can't be easily used either, because local functions don't support attributes until C# 9. The simplest thing here seems to be to use the null-forgiving operator, because the return value is used safely in the code below.