Fixed nullable embedded types are being added to generated resolver by Scormave · Pull Request #1556 · MessagePack-CSharp/MessagePack-CSharp · GitHub
Skip to content

Fixed nullable embedded types are being added to generated resolver#1556

Merged
AArnott merged 2 commits into
MessagePack-CSharp:developfrom
Shapes-R-D:fixNullableKnownTypes
Mar 11, 2023
Merged

Fixed nullable embedded types are being added to generated resolver#1556
AArnott merged 2 commits into
MessagePack-CSharp:developfrom
Shapes-R-D:fixNullableKnownTypes

Conversation

@Scormave

@Scormave Scormave commented Jan 26, 2023

Copy link
Copy Markdown

If some embedded reference type, such as byte[] is defined as nullable in MessagePackObject, it starts to appear in generated resolver. But, generated formatter for byte[] (ArrayFormatter) is not binary compatible with embedded formatter (ByteArrayFormatter).
This is what is generated from NullableTest before the fix:

        static GeneratedResolverGetFormatterHelper()
        {
            lookup = new global::System.Collections.Generic.Dictionary<global::System.Type, int>(18)
            {
                { typeof(byte[]), 0 },
                { typeof(global::System.Collections.Generic.List<byte[]>), 1 },
                { typeof(global::System.Collections.Generic.List<global::TestData2.A>), 2 },
                { typeof(global::System.Collections.Generic.List<global::TestData2.B>), 3 },
                { typeof(int[]), 4 },
                { typeof(global::TestData2.Nest1.Id), 5 },
                { typeof(global::TestData2.Nest2.Id), 6 },
                { typeof(global::TestData2.A), 7 },
                { typeof(global::TestData2.B), 8 },
                { typeof(global::TestData2.C), 9 },
                { typeof(global::TestData2.Nest1), 10 },
                { typeof(global::TestData2.Nest1.IdType), 11 },
                { typeof(global::TestData2.Nest2), 12 },
                { typeof(global::TestData2.Nest2.IdType), 13 },
                { typeof(global::TestData2.NullableTest), 14 },
                { typeof(global::TestData2.PropNameCheck1), 15 },
                { typeof(global::TestData2.PropNameCheck2), 16 },
                { typeof(global::TestData2.Record), 17 },
            };
        }

After the fix it looks like this:

        static GeneratedResolverGetFormatterHelper()
        {
            lookup = new global::System.Collections.Generic.Dictionary<global::System.Type, int>(16)
            {
                { typeof(global::System.Collections.Generic.List<byte[]>), 0 },
                { typeof(global::System.Collections.Generic.List<global::TestData2.A>), 1 },
                { typeof(global::System.Collections.Generic.List<global::TestData2.B>), 2 },
                { typeof(global::TestData2.Nest1.Id), 3 },
                { typeof(global::TestData2.Nest2.Id), 4 },
                { typeof(global::TestData2.A), 5 },
                { typeof(global::TestData2.B), 6 },
                { typeof(global::TestData2.C), 7 },
                { typeof(global::TestData2.Nest1), 8 },
                { typeof(global::TestData2.Nest1.IdType), 9 },
                { typeof(global::TestData2.Nest2), 10 },
                { typeof(global::TestData2.Nest2.IdType), 11 },
                { typeof(global::TestData2.NullableTest), 12 },
                { typeof(global::TestData2.PropNameCheck1), 13 },
                { typeof(global::TestData2.PropNameCheck2), 14 },
                { typeof(global::TestData2.Record), 15 },
            };
        }

@AArnott

AArnott commented Mar 11, 2023

Copy link
Copy Markdown
Collaborator

@AArnott AArnott force-pushed the fixNullableKnownTypes branch from b7f4814 to 99ae5e1 Compare March 11, 2023 19:36
@AArnott AArnott merged commit 81199b1 into MessagePack-CSharp:develop Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants