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