Nullable Reference Types - #642
Merged
rexm merged 2 commits intoAug 5, 2026
Merged
Conversation
Member
|
What is the purpose? |
Contributor
Author
It may make it more obvious to the user of the library when Handlebars.Net expect something not to be If you are new to NRT you might read https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/nullable-analysis - it contains some use-cases and how describes how the tooling tries to help you |
TheConstructor
force-pushed
the
feature/nullable-references
branch
from
June 24, 2026 21:17
0acc55b to
2a6fdd7
Compare
This was referenced Aug 6, 2026
rexm
added a commit
that referenced
this pull request
Aug 6, 2026
…te-type Try-methods PR #642 annotated all Try* out-parameters with [MaybeNullWhen(false)] on a non-nullable T, which is the correct pattern for unconstrained generic type parameters (as in Dictionary<TKey,TValue>.TryGetValue) but not for concrete reference types. For concrete types, the BCL convention (e.g. Uri.TryCreate) is [NotNullWhen(true)] out T? - this also gives callers a compiler warning if they dereference the out value without checking the return value first, which MaybeNullWhen(false) on non-nullable T silently allows. Updates IHelperResolver, IObjectDescriptorProvider (and implementers), IFormatterProvider (and implementers), TypeExtensions.IsAssignableToGenericType, and BlockAccumulatorContext.IsDetachedClosingElement. Generic-TValue Try-methods (LookupSlim, DictionarySlim, FixedSizeDictionary, CascadeIndex, ObservableIndex) are left as-is since they correctly mirror the BCL generic pattern. Fixes #654
rexm
added a commit
that referenced
this pull request
Aug 6, 2026
…es PR PR #642 touched two public readonly array field declarations (adding `?` annotations) without changing their design, which caused SonarCloud to flag S3887 ("non-private readonly field exposes mutable array") as new Bug-type issues on both lines, dropping the reliability rating from A to B. - Closure.A: made internal, since Closure's constructor is already internal and the field is unreachable by external consumers. Added InternalsVisibleTo("Handlebars.Test") for the one test that reads it directly, and pass BindingFlags.NonPublic to the reflection GetField call that resolves this field for compiled closure expressions. - PathInfo.Segments: left public with a NOSONAR suppression instead, since PathInfo instances do reach public surfaces (HelperOptions, PathExpression, etc.) and the field has been public since 2020 - flipping it to internal would be a real breaking change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I tried my best to annotate everything with Nullable Reference Annotations, and to convince the compiler of them (i.e. move assignments to the expected positions, ...). It's definitely a big PR. Sorry.