From db1175e45517b95059f07617f27fb7f94cdae29d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 22 Dec 2021 19:58:22 +0200 Subject: [PATCH] parser: handle `[noreturn]` on methods too --- ...ethod_can_be_used_instead_of_panic.run.out | 1 + ...urn_method_can_be_used_instead_of_panic.vv | 19 +++++++++++++++++++ vlib/v/parser/fn.v | 1 + 3 files changed, 21 insertions(+) create mode 100644 vlib/v/checker/tests/run/noreturn_method_can_be_used_instead_of_panic.run.out create mode 100644 vlib/v/checker/tests/run/noreturn_method_can_be_used_instead_of_panic.vv diff --git a/vlib/v/checker/tests/run/noreturn_method_can_be_used_instead_of_panic.run.out b/vlib/v/checker/tests/run/noreturn_method_can_be_used_instead_of_panic.run.out new file mode 100644 index 0000000000..2b92586664 --- /dev/null +++ b/vlib/v/checker/tests/run/noreturn_method_can_be_used_instead_of_panic.run.out @@ -0,0 +1 @@ +Test.zz_exit called, as it should diff --git a/vlib/v/checker/tests/run/noreturn_method_can_be_used_instead_of_panic.vv b/vlib/v/checker/tests/run/noreturn_method_can_be_used_instead_of_panic.vv new file mode 100644 index 0000000000..581b5e645e --- /dev/null +++ b/vlib/v/checker/tests/run/noreturn_method_can_be_used_instead_of_panic.vv @@ -0,0 +1,19 @@ +struct Test {} + +[noreturn] +fn (mut t Test) zz_exit() { + println('${@METHOD} called, as it should') + flush_stdout() + exit(0) +} + +fn optional() ?int { + return error('oh no') +} + +fn main() { + mut test := Test{} + a := optional() or { test.zz_exit() } + println(a) + exit(1) +} diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 5ee8777dcd..1f2dcdea67 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -399,6 +399,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl { generic_names: generic_names is_pub: is_pub is_deprecated: is_deprecated + is_noreturn: is_noreturn is_unsafe: is_unsafe is_main: is_main is_test: is_test