diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v index fe5f6d1b64..ffec50cf68 100644 --- a/vlib/v/gen/c/auto_str_methods.v +++ b/vlib/v/gen/c/auto_str_methods.v @@ -834,6 +834,9 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri if field.typ in ast.charptr_types { fn_builder.write_string('tos2((byteptr)$func)') } else { + if field.typ.is_ptr() && sym.kind == .struct_ { + fn_builder.write_string('(indent_count > 25) ? _SLIT("") : ') + } fn_builder.write_string(func) } } diff --git a/vlib/v/tests/str_circular_test.v b/vlib/v/tests/str_circular_test.v new file mode 100644 index 0000000000..7479937b2b --- /dev/null +++ b/vlib/v/tests/str_circular_test.v @@ -0,0 +1,21 @@ +[heap] +struct Aa { +mut: + bs []Bb +} + +struct Bb { +mut: + a &Aa +} + +fn test_circular() { + mut b := Bb{ + a: &Aa{ + bs: []Bb{cap: 1} + } + } + b.a.bs << b + s := b.str() + assert s.len < 3500 +}