From 9e6773cba8ec616e7d1d05122c8ecd85cb571b15 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 21 Feb 2020 17:52:20 +0100 Subject: [PATCH] fmt: optionals; none --- vlib/v/fmt/fmt.v | 3 +++ vlib/v/fmt/tests/simple_expected.vv | 4 ++++ vlib/v/fmt/tests/simple_input.vv | 6 +++--- vlib/v/table/atype_symbols.v | 6 +++++- 4 files changed, 15 insertions(+), 4 deletions(-) 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 }