From 1e88b1ab3ecea6d9195fbbbbd702de68837b7e7c Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Thu, 18 May 2023 06:25:19 -0300 Subject: [PATCH] cgen: fix missing panic message for 'option not set' on debug (#18168) --- vlib/v/gen/c/cgen.v | 2 +- vlib/v/slow_tests/inout/option_panic.out | 5 +++++ vlib/v/slow_tests/inout/option_panic.vv | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 vlib/v/slow_tests/inout/option_panic.out create mode 100644 vlib/v/slow_tests/inout/option_panic.vv diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 85434893ee..fd958d8007 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5958,7 +5958,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty err_msg := 'IError_name_table[${cvar_name}.err._typ]._method_msg(${cvar_name}.err._object)' if g.pref.is_debug { paline, pafile, pamod, pafn := g.panic_debug_info(or_block.pos) - g.writeln('panic_debug(${paline}, tos3("${pafile}"), tos3("${pamod}"), tos3("${pafn}"), ${err_msg} );') + g.writeln('panic_debug(${paline}, tos3("${pafile}"), tos3("${pamod}"), tos3("${pafn}"), ${err_msg}.len == 0 ? _SLIT("option not set ()") : ${err_msg});') } else { g.writeln('\tpanic_option_not_set( ${err_msg} );') } diff --git a/vlib/v/slow_tests/inout/option_panic.out b/vlib/v/slow_tests/inout/option_panic.out new file mode 100644 index 0000000000..d80b7e2f97 --- /dev/null +++ b/vlib/v/slow_tests/inout/option_panic.out @@ -0,0 +1,5 @@ +================ V panic ================ + module: main + function: main() + message: option not set () + file: vlib/v/slow_tests/inout/option_panic.vv:7 \ No newline at end of file diff --git a/vlib/v/slow_tests/inout/option_panic.vv b/vlib/v/slow_tests/inout/option_panic.vv new file mode 100644 index 0000000000..30768d355c --- /dev/null +++ b/vlib/v/slow_tests/inout/option_panic.vv @@ -0,0 +1,8 @@ +fn t() ? { + a := ?string(none) + println(a?) +} + +fn main() { + t()? +}