Skip to content

Commit fd07f7d

Browse files
authored
cgen: fix printing struct having fields of arrays of anonymous structs (#16953)
1 parent 41b9e51 commit fd07f7d

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

vlib/v/checker/tests/comptime_dump_fields_var_test.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[vlib/v/checker/tests/comptime_dump_fields_var_test.vv:13] val.$field.name: d
33
[vlib/v/checker/tests/comptime_dump_fields_var_test.vv:13] val.$field.name: 1
44
[vlib/v/checker/tests/comptime_dump_fields_var_test.vv:13] val.$field.name: 0
5-
[vlib/v/checker/tests/comptime_dump_fields_var_test.vv:13] val.$field.name: _VAnonStruct1{
5+
[vlib/v/checker/tests/comptime_dump_fields_var_test.vv:13] val.$field.name: struct {
66
i: 100
77
}
8-
ok
8+
ok

vlib/v/gen/c/auto_str_methods.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, typ_str string,
829829
g.auto_fn_definitions << fn_builder.str()
830830
}
831831
fn_builder.writeln('static string indent_${str_fn_name}(${styp} it, int indent_count) {')
832-
clean_struct_v_type_name := util.strip_main_name(typ_str)
832+
clean_struct_v_type_name := if info.is_anon { 'struct ' } else { util.strip_main_name(typ_str) }
833833
// generate ident / indent length = 4 spaces
834834
if info.fields.len == 0 {
835835
fn_builder.writeln('\treturn _SLIT("${clean_struct_v_type_name}{}");')
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Abc{
2+
a: [struct {
3+
b: 'this is b'
4+
}]
5+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
struct Abc {
2+
a []struct {
3+
b string
4+
}
5+
}
6+
7+
fn main() {
8+
abc := Abc{
9+
a: [struct {'this is b'}]
10+
}
11+
12+
println(abc)
13+
}

0 commit comments

Comments
 (0)