Skip to content

Commit

Permalink
Fix type wrapping order
Browse files Browse the repository at this point in the history
Types were being wrapped inside out, i.e. if you have some nested type A.B.C.D, the partial type
for D was being synthesized as C.B.A.D. This fixes the order for both serialization and deserialization.
  • Loading branch information
agocke committed Feb 4, 2024
1 parent a4b0028 commit 8af0528
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/generator/TypeDeclContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public TypeDeclContext(BaseTypeDeclarationSyntax typeDecl)
break;
}
}
nsNames.Reverse();
parentTypeInfos.Reverse();
NamespaceNames = nsNames;
ParentTypeInfo = parentTypeInfos;
TypeParameterList = typeDecl is TypeDeclarationSyntax derived
Expand Down
24 changes: 24 additions & 0 deletions test/Serde.Generation.Test/DeserializeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,30 @@ public enum ColorULong : ulong { Red = 3, Green = 5, Blue = 7 }
return GeneratorTestUtils.VerifyMultiFile(src);
}

[Fact]
public Task NestedPartialClasses()
{
var src = """
using Serde;

partial class A
{
private partial class B
{
private partial class C
{
[GenerateDeserialize]
private partial class D
{
public int Field;
}
}
}
}
""";
return VerifyDeserialize(src);
}

private static Task VerifyDeserialize(
string src,
[CallerMemberName] string caller = "")
Expand Down
24 changes: 24 additions & 0 deletions test/Serde.Generation.Test/SerializeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,30 @@ public enum Rgb { Red, Green, Blue }
return VerifyMultiFile(src);
}

[Fact]
public Task NestedPartialClasses()
{
var src = """
using Serde;

partial class A
{
private partial class B
{
private partial class C
{
[GenerateSerialize]
private partial class D
{
public int Field;
}
}
}
}
""";
return VerifySerialize(src);
}

private static Task VerifySerialize(
string src,
[CallerMemberName] string callerName = "")
Expand Down

0 comments on commit 8af0528

Please sign in to comment.