You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When mapping from a nullable type (either struct or class) to a type that has an implicit operator, mapperly incorrectly generates null handling checks. This occurs both when mapping directly, as in the example below, or when mapping a class with properties of this type.
As the implicit operator can take a nullable type, I would expect the nullable value to be passed in without the null check.
In cases where the implicit operator can't take a nullable type (e.g., int? to TrackedProperty in the example below), the current behaviour of generating the null check is correct.
Declaration code
using Riok.Mapperly.Abstractions;[Mapper]publicpartialclassSimple1{publicstaticpartialTrackedProperty<int?>ToFoo(int?source);}[Mapper]publicpartialclassSimple2{publicstaticpartial Dst ToFoo(Srcsource);}publicclassSrc{publicint?Foo{get;set;}}publicclassDst{publicTrackedProperty<int?> Foo {get;set;}}publicreadonlyrecordstructTrackedProperty<T>{privatereadonlyTvalue;publicTrackedProperty(Tvalue){this.value =value;}publicstaticimplicitoperatorTrackedProperty<T>(Tvalue){returnnewTrackedProperty<T>(value);}}
Environment (please complete the following information):
Mapperly Version: 3.6.0/4.0.0-next.3
Nullable reference types: enabled
.NET Version: .net framework 4.8/.net 8
Target Framework: .net standard 2.0/.net framework 4.8/.net 8
Compiler Version: 4.11.0-3.24365.8 (9e9c7c1d)
C# Language Version: 12
IDE: Visual Studio v17.10.5/Rider 2024.2.4
OS: Windows 11
Additional context
We have a partial workaround by declaring a user-implemented mapping, however we seem to be unable to create a generic user-implemented mapper.
// This does not workpublicstaticTrackedProperty<T>UserMap<T>(Tsource)=> source;// This does, but requires a separate function per typepublicstaticTrackedProperty<int?>UserMap(int?source)=> source;
The text was updated successfully, but these errors were encountered:
Describe the bug
When mapping from a nullable type (either struct or class) to a type that has an implicit operator, mapperly incorrectly generates null handling checks. This occurs both when mapping directly, as in the example below, or when mapping a class with properties of this type.
As the implicit operator can take a nullable type, I would expect the nullable value to be passed in without the null check.
In cases where the implicit operator can't take a nullable type (e.g., int? to TrackedProperty in the example below), the current behaviour of generating the null check is correct.
Declaration code
Actual relevant generated code
Expected relevant generated code
Environment (please complete the following information):
Additional context
We have a partial workaround by declaring a user-implemented mapping, however we seem to be unable to create a generic user-implemented mapper.
The text was updated successfully, but these errors were encountered: