Skip to content

Some source generator issues #1862

Description

@AlanLiu90

Bug description

  1. For the following type, formatter for A[] is missing in source generated resolver
[MessagePackObject]
public partial struct A
{
    [Key(0)]
    public int Id { get; set; }
}

[MessagePackObject]
public partial class B
{
    [Key(0)]
    public A Value1 { get; set; }

    [Key(1)]
    public A[] Value2 { get; set; }
}
  1. For the following type, the namespace of source generated composite resolver isn't complete
namespace TestProject2.X
{
    [CompositeResolver(typeof(MyResolver), typeof(StandardResolver))]
    public partial class MyCompositeResolver
    {
    }
}
  1. For the following type, formatter for List<int> is missing in source generated resolver
[MessagePackObject]
public partial class A
{
    [Key(0)]
    public List<bool> Value0 { get; set; }

    [Key(1)]
    public List<int> Value1 { get; set; }
}
  1. For the following type, only formatter for int[] is included in source generated resolver
[MessagePackObject]
public partial class A
{
    [Key(0)]
    public int[] Value1 { get; set; }

    [Key(1)]
    public int[,] Value2 { get; set; }

    [Key(2)]
    public int[,,] Value3 { get; set; }

    [Key(3)]
    public int[,,,] Value4 { get; set; }
}
  1. For the following type, formatter for List<int> is missing in source generated resolver and the generated code can't be compiled successfully
[MessagePackObject]
public partial class A
{
    [Key(0)]
    public List<int>[] Value { get; set; }
}

Repro steps

I created a repro for these issues:

Expected behavior

// V2 generated code
lookup = new global::System.Collections.Generic.Dictionary<global::System.Type, int>(3)
{
    { typeof(global::TestProject1.A[]), 0 },
    { typeof(global::TestProject1.A), 1 },
    { typeof(global::TestProject1.B), 2 },
};
namespace TestProject2.X {

partial class MyCompositeResolver : MsgPack::IFormatterResolver
{
	// ...
}

}
// V2 generated code
lookup = new global::System.Collections.Generic.Dictionary<global::System.Type, int>(3)
{
    { typeof(global::System.Collections.Generic.List<bool>), 0 },
    { typeof(global::System.Collections.Generic.List<int>), 1 },
    { typeof(global::TestProject3_v2.A), 2 },
};
// V2 generated code
lookup = new global::System.Collections.Generic.Dictionary<global::System.Type, int>(4)
{
    { typeof(int[,,,]), 0 },
    { typeof(int[,,]), 1 },
    { typeof(int[,]), 2 },
    { typeof(global::TestProject4_v2.A), 3 },
};
// V2 generated code
lookup = new global::System.Collections.Generic.Dictionary<global::System.Type, int>(3)
{
    { typeof(global::System.Collections.Generic.List<int>), 0 },
    { typeof(global::System.Collections.Generic.List<int>[]), 1 },
    { typeof(global::TestProject5_v2.A), 2 },
};

case 1: return new global::MessagePack.Formatters.ArrayFormatter<global::System.Collections.Generic.List<int>>();

Actual behavior

private static readonly global::System.Collections.Generic.Dictionary<global::System.Type, int> closedTypeLookup = new(2)
{
	{ typeof(global::TestProject1.B), 0 },
	{ typeof(global::TestProject1.A), 1 },
};
namespace X {

partial class MyCompositeResolver : MsgPack::IFormatterResolver
{
	// ...
}

}
private static readonly global::System.Collections.Generic.Dictionary<global::System.Type, int> closedTypeLookup = new(2)
{
	{ typeof(global::System.Collections.Generic.List<bool>), 0 },
	{ typeof(global::TestProject3_v3.A), 1 },
};
private static readonly global::System.Collections.Generic.Dictionary<global::System.Type, int> closedTypeLookup = new(2)
{
	{ typeof(global::System.Int32[]), 0 },
	{ typeof(global::TestProject4_v3.A), 1 },
};
private static readonly global::System.Collections.Generic.Dictionary<global::System.Type, int> closedTypeLookup = new(2)
{
	{ typeof(global::System.Collections.Generic.List<int>[]), 0 },
	{ typeof(global::TestProject5_v3.A), 1 },
};

0 => new MsgPack::Formatters.ArrayFormatter<global::System.Collections.Generic.List<T>>(),
  • Version used: 3.0.54-alpha
  • Runtime: .net6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions