From ee66c72a61fa55310cf8fe8e1b0ead03f8537f66 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 22 Jan 2025 19:19:07 -0300 Subject: [PATCH 1/2] fix --- vlib/v/gen/c/auto_str_methods.v | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v index 8a25ce27e6a123..89ac948c558f68 100644 --- a/vlib/v/gen/c/auto_str_methods.v +++ b/vlib/v/gen/c/auto_str_methods.v @@ -203,7 +203,8 @@ fn (mut g Gen) gen_str_for_option(typ ast.Type, styp string, str_fn_name string) g.auto_str_funcs.writeln('\tstring res;') g.auto_str_funcs.writeln('\tif (it.state == 0) {') deref := if typ.is_ptr() { - '**(${sym.cname}**)&' + dot := if expects_ptr { '*'.repeat(typ.nr_muls()) } else { '*'.repeat(typ.nr_muls() + 1) } + '${dot}(${sym.cname}**)&' } else if expects_ptr { '(${sym.cname}*)' } else { From 5d106389d6aba1ba9db68937535e65e8e5360b07 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Thu, 23 Jan 2025 07:52:07 -0300 Subject: [PATCH 2/2] add test --- vlib/v/tests/printing/print_option_ref_test.v | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 vlib/v/tests/printing/print_option_ref_test.v diff --git a/vlib/v/tests/printing/print_option_ref_test.v b/vlib/v/tests/printing/print_option_ref_test.v new file mode 100644 index 00000000000000..b93cbbbab413d9 --- /dev/null +++ b/vlib/v/tests/printing/print_option_ref_test.v @@ -0,0 +1,19 @@ +import net.html + +fn test_nil() { + mut doc := html.parse('') + footer := doc.get_tags_by_class_name('Box-footer')[0] + hrefs := footer.get_tag_by_class_name('Truncate') + println(hrefs) + res := '${hrefs}' + assert res == '&Option(&nil)' +} + +fn test_non_nil() { + mut doc := html.parse('') + footer := doc.get_tags_by_class_name('Box-footer')[0] + hrefs := footer.get_tag_by_class_name('Truncate') + println(hrefs) + res := '${hrefs}' + assert res == '&Option(
abc
)' +}