Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@faddiv
Copy link
Contributor

@faddiv faddiv commented Oct 11, 2025

Handle empty path in RootName

Description

This PR fixes the crash when the target is fullname but only has a single part. (f.e, Class only)
I'm unsure what it should do if it is a single part. For now, I made the simplest fix, but it doesn't really feel right.

I also created a test when the source property is a single part. This also behaves oddly:

  • If the destination is a string, then it generates this: destination.StringProperty = source.ToString() Is this intentional?
  • If it is not, then the map fails.

Fixes #1906

Checklist

  • 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)

@latonz latonz added the bug Something isn't working label Oct 15, 2025
@latonz
Copy link
Contributor

latonz commented Oct 15, 2025

Thanks for the contribution, this is actually the correct handling.
A single-part fullname should indeed be treated as a valid case, and your fix ensures we don’t crash while still covering that scenario correctly.

Regarding the source.ToString() behavior: yes, that’s intentional. When the destination is a string and the source is a non-string type, Mapperly converts it via ToString() by design. If it’s not a string, the mapping is expected to fail since there’s no implicit conversion.

@latonz latonz merged commit 5a68469 into riok:main Oct 15, 2025
19 of 20 checks passed
@latonz latonz changed the title fix: handle empty path in RootName fix: handle single segment fullnameof Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

If MapProperty.Target is a nameof with single value mappery crashes

2 participants