mapperly
mapperly copied to clipboard
Diagnostic for mapping null mismatch
Emit a diagnostic if the source is nullable but the target isn't. Default severity should be info.
Proposed message: Mapping the nullable source property {0} of {1} to the target property {2} of {3} which is not nullable
Relates https://github.com/riok/mapperly/discussions/375
If you add this, please make it possible to suppress this diagnostic for a single member. So that I can say "I know this, it's fine".
Please, prioritize this issue. I would find it very useful and development without it is not compile time safe.
In my opinion, Mapperly is compile-safe without this feature, as all generated code is type-safe and provides diagnostics for invalid mappings. I can still understand your need for this feature, as it would definitely be a nice addition. However, this is not currently high on our priority list. With only one :+1: reaction, it also doesn't seem to be one of the most important features missing by the community... You are always welcome to contribute, we will support you with tips and reviews. If you cannot wait for this feature and do not have the time to implement it yourself, we are open to discussing sponsorship for specific features.
Thanks for the quick reply!
I'm sorry, I didn't mean to say that "the code that Mapperly produces is not compile-time safe" in any way. What I meant is that:
- When a property in the source class is nullable but not in the target class, and the actual value is null, the resulting value assigned to the target property will be the default for it's type. This can produce unexpected behaviour (in the case of value types) or errors (in the case of reference types in a [nullable enable] context). That is why I think a diagnostic that warns you when this is happening is very important.
After writing my previous comment I discovered that in the 4.0.0-next.1 preview documentation there is a new diagnostic, RMG076
, that seems to address this (?). It's description is "Cannot assign null to non-nullable member.". I will try it whenever I can, but what's your comment on that?
Thanks again!
We definitely want to implement this diagnostic, it's just not on top of our priority list 😊
RMG076
is only for MapValue
...
Okay, I understand. Thanks anyway! ❤️
Hey @latonz, I would like to work on this, could you assign me? 😄