1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix printing struct having fields of arrays of anonymous structs (#16953)

This commit is contained in:
yuyi 2023-01-14 06:41:31 +08:00 committed by GitHub
parent 41b9e513ca
commit fd07f7df69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 3 deletions

View File

@ -2,7 +2,7 @@
[vlib/v/checker/tests/comptime_dump_fields_var_test.vv:13] val.$field.name: d
[vlib/v/checker/tests/comptime_dump_fields_var_test.vv:13] val.$field.name: 1
[vlib/v/checker/tests/comptime_dump_fields_var_test.vv:13] val.$field.name: 0
[vlib/v/checker/tests/comptime_dump_fields_var_test.vv:13] val.$field.name: _VAnonStruct1{
[vlib/v/checker/tests/comptime_dump_fields_var_test.vv:13] val.$field.name: struct {
i: 100
}
ok
ok

View File

@ -829,7 +829,7 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, typ_str string,
g.auto_fn_definitions << fn_builder.str()
}
fn_builder.writeln('static string indent_${str_fn_name}(${styp} it, int indent_count) {')
clean_struct_v_type_name := util.strip_main_name(typ_str)
clean_struct_v_type_name := if info.is_anon { 'struct ' } else { util.strip_main_name(typ_str) }
// generate ident / indent length = 4 spaces
if info.fields.len == 0 {
fn_builder.writeln('\treturn _SLIT("${clean_struct_v_type_name}{}");')

View File

@ -0,0 +1,5 @@
Abc{
a: [struct {
b: 'this is b'
}]
}

View File

@ -0,0 +1,13 @@
struct Abc {
a []struct {
b string
}
}
fn main() {
abc := Abc{
a: [struct {'this is b'}]
}
println(abc)
}