checker: fix match branch checking of nonreturn call on last expr (fix #23698) (#23699)

This commit is contained in:
Felipe Pena 2025-02-12 10:45:42 -03:00 committed by GitHub
parent 02ca30acf0
commit 92f436db12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 1 deletions

View File

@ -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]

View File

@ -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)
}