From 29511bcc49ae33c375bacae69887e125232a0bd3 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 19 Oct 2023 17:40:04 +0800 Subject: [PATCH] ast: fix segfault while formatting a struct declaration with a nested struct (#19592) --- vlib/v/ast/table.v | 4 ++-- vlib/v/fmt/tests/struct_decl_with_nested_struct_keep.vv | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 vlib/v/fmt/tests/struct_decl_with_nested_struct_keep.vv diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 05903ffb3..8e2ac86fe 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -1378,8 +1378,8 @@ pub fn (t &Table) has_deep_child_no_ref(ts &TypeSymbol, name string) bool { if ts.info is Struct { for field in ts.info.fields { sym := t.sym(field.typ) - if !field.typ.is_ptr() && ((sym.name == name && !field.typ.has_flag(.option)) - || t.has_deep_child_no_ref(sym, name)) { + if !field.typ.is_ptr() && !field.typ.has_flag(.option) + && (sym.name == name || t.has_deep_child_no_ref(sym, name)) { return true } } diff --git a/vlib/v/fmt/tests/struct_decl_with_nested_struct_keep.vv b/vlib/v/fmt/tests/struct_decl_with_nested_struct_keep.vv new file mode 100644 index 000000000..d93057ced --- /dev/null +++ b/vlib/v/fmt/tests/struct_decl_with_nested_struct_keep.vv @@ -0,0 +1,7 @@ +pub struct Node { + parent ?Node +} + +pub struct NodeWrapper { + node Node +} -- 2.39.5