checker: comptime match only eval true branch (fix #25223) (#25225)

This commit is contained in:
kbkpbot 2025-09-04 18:33:39 +08:00 committed by GitHub
parent f17e0fd52b
commit e15d8fcf49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 4 deletions

View file

@ -221,11 +221,14 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
}
}
}
if !node.is_comptime || (node.is_comptime && comptime_match_branch_result) {
if node.is_expr {
c.stmts_ending_with_expression(mut branch.stmts, c.expected_or_type)
} else {
c.stmts(mut branch.stmts)
}
}
c.smartcast_mut_pos = token.Pos{}
c.smartcast_cond_pos = token.Pos{}
if node.is_expr {

View file

@ -0,0 +1,17 @@
module main
fn func[T]() bool {
$match T {
u8, u16 {
return true
}
$else {
// return false
$compile_error('fail')
}
}
}
fn test_comptime_match_eval_only_true_branch() {
assert func[u8]()
}