From 962bbf1c607176781f50bd6d5f28c000bb9b485d Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 3 Jun 2020 23:45:40 +0800 Subject: [PATCH] fmt: fix ?void format error, add _keep.vv test --- vlib/v/fmt/tests/void_optional_keep.vv | 9 +++++++++ vlib/v/table/atypes.v | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 vlib/v/fmt/tests/void_optional_keep.vv diff --git a/vlib/v/fmt/tests/void_optional_keep.vv b/vlib/v/fmt/tests/void_optional_keep.vv new file mode 100644 index 0000000000..32cb28ea76 --- /dev/null +++ b/vlib/v/fmt/tests/void_optional_keep.vv @@ -0,0 +1,9 @@ +fn tt() ? { + return error('error') +} + +fn main() { + tt() or { + panic('$err') + } +} diff --git a/vlib/v/table/atypes.v b/vlib/v/table/atypes.v index 2debd28297..7d350791c1 100644 --- a/vlib/v/table/atypes.v +++ b/vlib/v/table/atypes.v @@ -707,7 +707,11 @@ pub fn (table &Table) type_to_str(t Type) string { res = strings.repeat(`&`, nr_muls) + res } if t.flag_is(.optional) { - res = '?' + res + if sym.kind == .void { + res = '?' + } else { + res = '?' + res + } } /* if res.starts_with(cur_mod +'.') {