mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix json.encode of a struct containing a field of an alias type of another struct (#15490)
This commit is contained in:
parent
f727433929
commit
47e75c68a9
@ -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}}'
|
||||
}
|
||||
|
@ -436,7 +436,7 @@ fn (mut g Gen) gen_struct_enc_dec(type_info ast.TypeInfo, styp string, mut enc s
|
||||
}
|
||||
dec.writeln('\t}')
|
||||
} else {
|
||||
g.gen_json_for_type(field.typ)
|
||||
g.gen_json_for_type(alias.parent_type)
|
||||
tmp := g.new_tmp_var()
|
||||
gen_js_get_opt(dec_name, field_type, styp, tmp, name, mut dec, is_required)
|
||||
dec.writeln('\tif (jsonroot_$tmp) {')
|
||||
|
Loading…
Reference in New Issue
Block a user