Repository navigation
fix: use null-conditional access for nested source in existing target mappings - #2498
Open
EnesKartal wants to merge 1 commit into
Open
EnesKartal wants to merge 1 commit into
EnesKartal wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Description
When mapping a nested source member onto an existing target member (such as a readonly collection),
MemberExistingTargetMappingpreviously built a non-null-conditional source access (source.Nested.Items) and passed it directly intoNullDelegateExistingTargetMapping. When an intermediate parent in the source path was null, the generated guardif (source.Nested.Items != null && target.Items != null)threw aNullReferenceException(and could trigger CS8602 when nullable reference types are enabled).This change:
Buildoverload onNullDelegateExistingTargetMappingthat accepts a null-safe source expression for the null guard while using the unwrapped source access inside the guarded body.MemberExistingTargetMapping.Buildto use null-conditional access (e.g.,source.Nested?.Items != null) when any parent in the source member path is nullable, handles nullable value-type parents properly, and guards non-nullable delegate mappings.EnumerableExistingTargetTestcovering disabled nullable context, nullable reference/struct parents, value-type enumerables, and user-implemented existing target methods.Fixes #2303
Checklist