fix: prevent delegation to inexact user mappings#2372
Open
AmirTahan80 wants to merge 1 commit into
Open
Conversation
Ignore user-defined mappings when resolving generalized delegated mappings, ensuring they are only used for exact source and target type matches. Add a regression test for riok#1793.
Author
|
Additional implementation context: this follows the approach proposed in #1793 by excluding The regression test uses the reported Validation completed locally:
|
AmirTahan80
marked this pull request as ready for review
July 18, 2026 10:30
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.
Fixes #1793.
Summary
Mapperly could reuse a user-defined mapping through
BuildDelegatedMappingeven when the requested source and target types did not match the user mapping exactly. For example, a mapping returningTarget[]could be selected when Mapperly neededIEnumerable<Target>.Root cause
MappingBuilderContext.BuildDelegatedMappingaccepted any existing mapping found for compatible types. This also includedIUserMappingimplementations, although user-defined mappings should only participate when their source and target types match exactly.Changes
IUserMappinginstances from generalized delegated mapping resolution.Impact
Mapperly now generates the appropriate collection and element mappings instead of selecting an inexact user-defined mapping. User mappings continue to work when their source and target types match exactly.
This changes the behavior of inexact user mappings and is therefore appropriate for the next major release, as discussed in the issue.
Validation
dotnet build Riok.Mapperly.slnx /p:TreatWarningsAsErrors=truedotnet test Riok.Mapperly.slnx --no-build --no-restore