diff --git a/vlib/v/checker/match.v b/vlib/v/checker/match.v index 976002db11e5b6..ba49aef36f3cc9 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 00000000000000..ac1df466f79ea5 --- /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) +}