diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 959add0010..fd08903303 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -562,7 +562,9 @@ pub fn (mut f Fmt) type_decl(node ast.TypeDecl) { f.write(')') if fn_info.return_type.idx() != table.void_type_idx { ret_str := f.no_cur_mod(f.table.type_to_str(fn_info.return_type)) - f.write(' ' + ret_str) + f.write(' $ret_str') + } else if fn_info.return_type.has_flag(.optional) { + f.write(' ?') } } ast.SumTypeDecl { diff --git a/vlib/v/fmt/tests/fntype_return_optional_expected.vv b/vlib/v/fmt/tests/fntype_return_optional_expected.vv new file mode 100644 index 0000000000..35c829e925 --- /dev/null +++ b/vlib/v/fmt/tests/fntype_return_optional_expected.vv @@ -0,0 +1,3 @@ +type Foo = fn (a int) ? + +type Foo2 = fn (num int) ?int diff --git a/vlib/v/fmt/tests/fntype_return_optional_input.vv b/vlib/v/fmt/tests/fntype_return_optional_input.vv new file mode 100644 index 0000000000..58bac90ca5 --- /dev/null +++ b/vlib/v/fmt/tests/fntype_return_optional_input.vv @@ -0,0 +1,3 @@ +type Foo = fn (a int)? + +type Foo2 = fn (num int)?int