-
-
Notifications
You must be signed in to change notification settings - Fork 201
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
The following
enum TargetEnum
{
Bar,
}
class Source
{
string Quux { get; set; }
}
class Target
{
string Quux { get; set; }
TargetEnum? TheTarget { get; set; }
}
[MapValue(nameof(Target.TheTarget), TargetEnum.Bar))
static partial Target Map(this Source source);incorrectly yields
RMG077: Cannot assign constant value TargetEnum.Bar of type TargetEnum to Target.TheTarget of type TargetEnum?
but should result in no error and valid generated code, because a non-null value of a type is always assignable to a nullable value of the same type.
The below cannot be used as a workaround, as typecasts are not permitted in attributes.
[MapValue(nameof(Target.TheTarget), (TargetEnum?)TargetEnum.Bar))The below is a valid workaround, but undesirable.
[MapValue(nameof(Target.TheTarget), Use = nameof(GetNullableTargetEnumValue)))
static partial Target Map(this Source source);
static TargetEnum? GetNullableTargetEnumValue() => TargetEnum.Bar;Environment (please complete the following information):
- Mapperly Version: 4.0.0
- Nullable reference types: enabled
- .NET Version: 8.0.403
- Target Framework: .net8.0
- Compiler Version: 4.11.0-3.24460.3 (5649376e)
- C# Language Version: 12.0
- IDE: VS2022.17.11.5
- OS: Windows 11 Pro 23H2 (22631.4169)
Additional context
#631
latonz
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working