vfmt: fix formatting for an option array of anon structs (fix #23841) (#23844)

This commit is contained in:
Felipe Pena 2025-03-02 05:16:02 -03:00 committed by GitHub
parent 57a45bc353
commit 8201b8a45f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View File

@ -169,6 +169,9 @@ fn (mut f Fmt) write_anon_struct_field_decl(field_typ ast.Type, field_anon_decl
elem_sym := f.table.sym(sym.info.elem_type)
if elem_sym.info is ast.Struct {
if elem_sym.info.is_anon {
if field_typ.has_flag(.option) {
f.write('?')
}
f.write('[]'.repeat(sym.info.nr_dims))
f.write_anon_struct_field_decl(sym.info.elem_type, field_anon_decl)
return true

View File

@ -0,0 +1,22 @@
module main
import json
struct Data {
mut:
a_token ?[]string
dfv ?[]struct {
key string
}
}
fn main() {
j := '{
"a_token2": ["one", "two"],
"a_email2": {
"email": "email@email.ru"
}
}'
d := json.decode(Data, j)!
println(d)
}