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

Invalid mapping for nullable arrays #1611

Open
TonEnfer opened this issue Nov 26, 2024 · 1 comment
Open

Invalid mapping for nullable arrays #1611

TonEnfer opened this issue Nov 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@TonEnfer
Copy link
Contributor

TonEnfer commented Nov 26, 2024

Describe the bug
Mapperly generates incorrect code for nullable arrays in some cases. See example code

Declaration code

public record Dto(int[]? Array);

[Mapper]
public partial class Mapper
{
    public partial Dto Map(int[]? array);
    public partial int[]? Map(int[]? model);
}

Actual relevant generated code

// <auto-generated />
#nullable enable
namespace ConsoleApp1
{
    public partial class Mapper
    {
        [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "4.1.1.0")]
        public partial global::ConsoleApp1.Dto Map(int[]? model)
        {
            return model == null ? throw new System.ArgumentNullException(nameof(model)) : new global::ConsoleApp1.Dto(model);
        }

        [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "4.1.1.0")]
        public partial int[]? Map(int[]? model)
        {
            return model == null ? default : model;
        }
    }
}

Expected relevant generated code

// <auto-generated />
#nullable enable
namespace ConsoleApp1
{
    public partial class Mapper
    {
        [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "4.1.1.0")]
        public partial global::ConsoleApp1.Dto Map(int[]? model)
        {
            return new global::ConsoleApp1.Dto(model);
        }

        [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "4.1.1.0")]
        public partial int[]? Map(int[]? model)
        {
            return model;
        }
    }
}

Environment (please complete the following information):

  • Mapperly Version: 4.1.1.0
  • Nullable reference types: enabled
  • .NET Version: 9.0.100
  • Target Framework: .net9.0
  • Compiler Version: 4.12.0-3.24558.5 (21192bfc)
  • C# Language Version: 13.0
  • IDE: Visual Studio 17.12.1
  • OS: Win 11
@TonEnfer TonEnfer added the bug Something isn't working label Nov 26, 2024
@latonz
Copy link
Contributor

latonz commented Nov 27, 2024

Thank you for reporting this issue! It seems there are some bugs related to our null handling. I've created #1614 to address this and explore ways to improve our approach to null handling in general.

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

No branches or pull requests

2 participants