cgen: fix json.encode of a struct containing a field of an alias type of another struct (#15490)

This commit is contained in:
yuyi 2022-08-22 16:04:58 +08:00 committed by GitHub
parent f727433929
commit 47e75c68a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -488,3 +488,23 @@ struct StByteArray {
fn test_byte_array() {
assert json.encode(StByteArray{ ba: [byte(1), 2, 3, 4, 5] }) == '{"ba":[1,2,3,4,5]}'
}
struct Aa {
sub SumType
}
struct Bb {
a int
}
type SumType = Bb
fn test_encode_alias_field() {
s := json.encode(Aa{
sub: SumType(Bb{
a: 1
})
})
println(s)
assert s == '{"sub":{"a":1}}'
}