Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RMG012 is emitted, while RequiredMapping is set to Source, using init-only properties #1685

Closed
PaulVrugt opened this issue Jan 15, 2025 · 1 comment · Fixed by #1686
Closed
Labels
bug Something isn't working

Comments

@PaulVrugt
Copy link

Please do the checklist before filing an issue:

  • [ x ] I have read the documentation, including the FAQ
  • [ x ] I can reproduce the bug using the latest prerelease version
  • [ x ] I have searched existing discussion and issue to avoid duplicates

Describe the bug
Using the latest version (4.1.1), when I use [MapperRequiredMapping(RequiredMappingStrategy.Source)] in a mapper, the mapper still complains about unmapped target properties when they have an init only setter.

Declaration code

public record Source
{
    public bool Property1 { get; set; }
}


public record Target
{
    public bool Property1 { get; init; }
    public bool Property2 { get; init; }
}

[Mapper]
public partial class ClassMapper
{
    [MapperRequiredMapping(RequiredMappingStrategy.Source)]
    public partial Target MapToEntityAuto(Source dto);
}

Actual relevant generated code

public partial class ClassMapper
{
    [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "4.1.1.0")]
    public partial global::Target MapToEntityAuto(global::Source dto)
    {
        var target = new global::Target()
        {
            Property1 = dto.Property1,
        };
        return target;
    }
}

Reported relevant diagnostics

  • RMG012: The member Property2 on the mapping target type Target was not found on the mapping source type Source

Environment (please complete the following information):

  • Mapperly Version: 4.1.1
  • Nullable reference types: enabled
  • .NET Version: .net 9.0
  • Target Framework: .net 9.0
  • Compiler Version: not sure
  • C# Language Version: latest
  • IDE: Visual Studio v17.12.3
  • OS: Windows 11

Additional context
As soon as you change the { get; init; } of property2 to { get; get; }, the error disappears

@PaulVrugt
Copy link
Author

you guys rock!

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 a pull request may close this issue.

1 participant