From 169627722ad1fb6ebe703ca1176e451a6dcddf9a Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Mon, 5 Jun 2023 10:45:44 -0300 Subject: [PATCH] cgen: circular reference limit to auto_str for interface (#18340) --- vlib/v/gen/c/auto_str_methods.v | 2 +- vlib/v/tests/option_ptr_iface_test.v | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/option_ptr_iface_test.v diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v index 6646594e57..fabf8f04eb 100644 --- a/vlib/v/gen/c/auto_str_methods.v +++ b/vlib/v/gen/c/auto_str_methods.v @@ -1007,7 +1007,7 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, lang ast.Language, styp strin if field.typ in ast.charptr_types { fn_body.write_string('tos4((byteptr)${func})') } else { - if field.typ.is_ptr() && sym.kind == .struct_ { + if field.typ.is_ptr() && sym.kind in [.struct_, .interface_] { funcprefix += '(indent_count > 25)? _SLIT("") : ' } // eprintln('>>> caller_should_free: ${caller_should_free:6s} | funcprefix: $funcprefix | func: $func') diff --git a/vlib/v/tests/option_ptr_iface_test.v b/vlib/v/tests/option_ptr_iface_test.v new file mode 100644 index 0000000000..47c7f2565f --- /dev/null +++ b/vlib/v/tests/option_ptr_iface_test.v @@ -0,0 +1,18 @@ +interface ITeste { +mut: + teste ?&ITeste +} + +struct Teste { +pub mut: + teste ?&ITeste +} + +fn test_main() { + mut t := Teste{} + t.teste = &t + z := &ITeste(t) + dump(z) + dump(t) + assert voidptr(t.teste?) == voidptr(z.teste?) +}