diff --git a/vlib/v/gen/c/struct.v b/vlib/v/gen/c/struct.v index e46f149512..e903adfb5a 100644 --- a/vlib/v/gen/c/struct.v +++ b/vlib/v/gen/c/struct.v @@ -321,7 +321,7 @@ fn (mut g Gen) zero_struct_field(field ast.StructField) bool { } g.write('.${field_name} = ') if field.typ.has_flag(.option) { - if field.is_recursive { + if field.is_recursive || field.typ.is_ptr() { g.expr_with_opt(ast.None{}, ast.none_type, field.typ) } else { tmp_var := g.new_tmp_var() diff --git a/vlib/v/tests/option_ptr_init_test.v b/vlib/v/tests/option_ptr_init_test.v new file mode 100644 index 0000000000..c45ea9f58e --- /dev/null +++ b/vlib/v/tests/option_ptr_init_test.v @@ -0,0 +1,12 @@ +struct Queue { + head ?&Node +} + +struct Node { + next ?&Node +} + +fn test_main() { + q := Queue{} + assert q.head == none +}