From 92f436db126fa31eb2f006722418c5c0a8925073 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 12 Feb 2025 10:45:42 -0300 Subject: [PATCH] checker: fix match branch checking of nonreturn call on last expr (fix #23698) (#23699) --- vlib/v/checker/match.v | 2 +- vlib/v/tests/panic_on_match_branch_test.v | 31 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/panic_on_match_branch_test.v diff --git a/vlib/v/checker/match.v b/vlib/v/checker/match.v index 976002db11..ba49aef36f 100644 --- a/vlib/v/checker/match.v +++ b/vlib/v/checker/match.v @@ -127,7 +127,7 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type { } } } - if stmt.typ != ast.error_type { + if stmt.typ != ast.error_type && !is_noreturn_callexpr(stmt.expr) { ret_sym := c.table.sym(ret_type) stmt_sym := c.table.sym(stmt.typ) if ret_sym.kind !in [.sum_type, .interface] diff --git a/vlib/v/tests/panic_on_match_branch_test.v b/vlib/v/tests/panic_on_match_branch_test.v new file mode 100644 index 0000000000..ac1df466f7 --- /dev/null +++ b/vlib/v/tests/panic_on_match_branch_test.v @@ -0,0 +1,31 @@ +module main + +pub struct Operand { +pub: + typ OperandType = .reg_state +} + +pub enum OperandType { + reg_self + reg_state +} + +struct Value { +} + +fn set_value(operand Operand, val2 &Value) { + val1 := match operand.typ { + .reg_state { + val2 + } + .reg_self { + panic('ERR') + } + } + assert val1.str() == val2.str() +} + +fn test_main() { + mut val := Value{} + set_value(Operand{}, &val) +}