diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index bd083a13ea..78d6070447 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -304,6 +304,9 @@ fn (f mut Fmt) expr(node ast.Expr) { } f.write(')') } + ast.None { + f.write('none') + } ast.PostfixExpr { f.expr(it.expr) f.write(it.op.str()) diff --git a/vlib/v/fmt/tests/simple_expected.vv b/vlib/v/fmt/tests/simple_expected.vv index e49b28a192..1d592ea307 100644 --- a/vlib/v/fmt/tests/simple_expected.vv +++ b/vlib/v/fmt/tests/simple_expected.vv @@ -69,3 +69,7 @@ fn (this User) fn_with_receiver() { x := if true { 1 } else { 2 } println('') } + +fn get_user() ?User { + return none +} diff --git a/vlib/v/fmt/tests/simple_input.vv b/vlib/v/fmt/tests/simple_input.vv index 6c5600253b..f286bf9bdd 100644 --- a/vlib/v/fmt/tests/simple_input.vv +++ b/vlib/v/fmt/tests/simple_input.vv @@ -74,6 +74,6 @@ fn (this User) fn_with_receiver() { println('') } -//fn get_user() ? User { - -//} +fn get_user() ? User { + return none +} diff --git a/vlib/v/table/atype_symbols.v b/vlib/v/table/atype_symbols.v index ffb5c3cd18..330a9978ee 100644 --- a/vlib/v/table/atype_symbols.v +++ b/vlib/v/table/atype_symbols.v @@ -395,5 +395,9 @@ pub mut: pub fn (table &Table) type_to_str(t Type) string { sym := table.get_type_symbol(t) - return sym.name.replace('array_', '[]') + mut res := sym.name.replace('array_', '[]') + if type_is_optional(t) { + res = '?' + res + } + return res }