Skip to content

feat: forward additional mapping method parameters#2193

Merged
latonz merged 32 commits intoriok:mainfrom
Demivan:parameter-mapping
Apr 10, 2026
Merged

feat: forward additional mapping method parameters#2193
latonz merged 32 commits intoriok:mainfrom
Demivan:parameter-mapping

Conversation

@Demivan
Copy link
Copy Markdown
Contributor

@Demivan Demivan commented Mar 19, 2026

Description

Additional parameters on mapping methods (beyond source/target/referenceHandler) are now forwarded to user-defined nested mapping methods, MapValue(Use=...), MapProperty(Use=...), and MapPropertyFromSource(Use=...) methods.
Works with queryable projections - additional parameters become captured variables in the generated expression.

Parameters are matched by name, but mappings to map them when types don't match are not generated. It is more complex to support that. Should I add type checks while that is not supported? Currently, parameter string ctx will match int ctx but will produce a non-compilable code.

Besides unit tests, I have tested it on real project and parameterized mapping methods and projections were generated correctly.

Note: I have used Claude, but I was steering is constantly - no vibecoding

Fixes #1472
Fixes #1765 (user needs to define mappings with parameters)

Supersedes #1946

Checklist

  • I did not use AI tools to generate this PR, or I have manually verified that the code is correct, optimal, and follows the project guidelines and architecture
  • I understand that low-quality, AI-generated PRs will be closed immediately without further explanation
  • The existing code style is followed
  • The commit message follows our guidelines
  • Performed a self-review of my code
  • Hard-to-understand areas of my code are commented
  • The documentation is updated (as applicable)
  • Unit tests are added/updated
  • Integration tests are added/updated (as applicable, especially if feature/bug depends on roslyn or framework version in use)

@Demivan Demivan force-pushed the parameter-mapping branch 8 times, most recently from 09facb6 to 4d0ce3d Compare March 22, 2026 18:00
@latonz latonz self-requested a review March 27, 2026 09:28
@latonz latonz added the enhancement New feature or request label Apr 9, 2026
Copy link
Copy Markdown
Contributor

@latonz latonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request, and for your patience. I was a bit out during the Easter holidays, but I’ve now added my feedback.

@Demivan Demivan force-pushed the parameter-mapping branch from 0d6cac2 to 3f503f6 Compare April 9, 2026 15:13
@Demivan Demivan requested a review from latonz April 9, 2026 15:15
Demivan added 17 commits April 9, 2026 18:24
…ilderContext

Always allow additional parameters in BuildUserImplementedMapping
(remove allowAdditionalParameters parameter — was true at all call
sites)
- MapPropertyFromSource(Use=...) unsatisfiable params → RMG097
- MapValue(Use=...) partially matching params → RMG096 + RMG082
- Nested mapping with multiple additional params
- MappingTarget + MapProperty(Use=...) with params
- Param consumed only by Use method → no false RMG082
- Param consumed only by nested mapping → no false RMG082
- Multiple unused params → multiple RMG082
- Init-only and constructor params from additional parameters
- Nested projection inlining with additional params
- Collection mapping test for additional parameter forwarding
fix: move diagnostics to AnalyzerReleases.Shipped.md and add diagnostic docs

Per contributing guidelines:
- Move RMG096/RMG097 from Unshipped to Shipped (Mapperly does not use Unshipped)
- Add RMG096.mdx and RMG097.mdx diagnostic documentation pages
…nal parameters

Projections with additional parameters now only pick up MapProperty/
MapPropertyFromSource configurations from element mappings whose
additional parameters match. No fallback to default element mappings
that ignore the parameters. Projections without additional parameters
continue to use the default element mapping as before.
…meters

feat: support additional parameters on external and MapPropertyFromSource Use methods

- Remove IsExternal guard from BuildArguments in
  UserImplementedMethodMapping and
  UserImplementedExistingTargetMethodMapping — external mapper methods
  now forward additional parameters like internal ones
- Always allow additional parameters in BuildUserImplementedMapping
  (remove allowAdditionalParameters parameter — was true at all call
  sites)
- Enable MapPropertyFromSource(Use=...) with additional parameters by
  discovering user-implemented methods with extra params during initial
  extraction
Demivan added 14 commits April 9, 2026 18:35
… ParameterScope

When a non-empty scope is passed, Find performs a parameterized-only
lookup; otherwise it does the regular dictionary lookup. This removes
the separate FindUserMappingWithParameters method from the entire chain.
…eterizedUserMapping

Mark parameters as used directly in FindByParameters, eliminating the
need for a separate FindParameterizedUserMapping wrapper. This simplifies
FindOrBuildMapping and FindOrBuildLooseNullableMapping cascades.
@Demivan Demivan force-pushed the parameter-mapping branch from 3f503f6 to fd3abff Compare April 9, 2026 15:46
@Demivan
Copy link
Copy Markdown
Contributor Author

Demivan commented Apr 9, 2026

@latonz, I have fixed the review comments and rebased on the latest main

Copy link
Copy Markdown
Contributor

@latonz latonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the updates! One nitpick left, then it looks good to merge 😊

@latonz latonz enabled auto-merge (squash) April 10, 2026 07:38
@latonz
Copy link
Copy Markdown
Contributor

latonz commented Apr 10, 2026

Thank you for this contribution to Mapperly 🥳

@latonz latonz merged commit c61a57a into riok:main Apr 10, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extra mapper parameters do not work with MapDerivedType Pass additional parameters to property mapper methods

2 participants