Skip to content

Commit

Permalink
checker: fix match branch checking of nonreturn call on last expr (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Feb 12, 2025
1 parent 02ca30a commit 92f436d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/checker/match.v
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
31 changes: 31 additions & 0 deletions vlib/v/tests/panic_on_match_branch_test.v
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 92f436d

Please sign in to comment.