diff --git a/vlib/v/fmt/tests/struct_with_fn_fields_keep.vv b/vlib/v/fmt/tests/struct_with_fn_fields_keep.vv new file mode 100644 index 0000000000..2f1bd98316 --- /dev/null +++ b/vlib/v/fmt/tests/struct_with_fn_fields_keep.vv @@ -0,0 +1,4 @@ +struct FieldsWithOptionalVoidReturnType { + f fn () ? + g fn () ? +} diff --git a/vlib/v/table/table.v b/vlib/v/table/table.v index fa4f65ed64..6535c0cb7c 100644 --- a/vlib/v/table/table.v +++ b/vlib/v/table/table.v @@ -120,7 +120,9 @@ pub fn (t &Table) fn_type_source_signature(f &Fn) string { } } sig += ')' - if f.return_type != void_type { + if f.return_type == ovoid_type { + sig += ' ?' + } else if f.return_type != void_type { return_type_sym := t.get_type_symbol(f.return_type) sig += ' $return_type_sym.name' } diff --git a/vlib/v/table/types.v b/vlib/v/table/types.v index 13b0d16ca5..ce97f1c1d4 100644 --- a/vlib/v/table/types.v +++ b/vlib/v/table/types.v @@ -335,6 +335,7 @@ pub const ( pub const ( void_type = new_type(void_type_idx) + ovoid_type = new_type(void_type_idx).set_flag(.optional) // the return type of `fn () ?` voidptr_type = new_type(voidptr_type_idx) byteptr_type = new_type(byteptr_type_idx) charptr_type = new_type(charptr_type_idx)