mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
checker: comptime match only eval true branch
This commit is contained in:
parent
f6b60e4d9f
commit
b442fc6349
2 changed files with 178 additions and 158 deletions
|
@ -221,6 +221,8 @@ 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 {
|
if node.is_expr {
|
||||||
c.stmts_ending_with_expression(mut branch.stmts, c.expected_or_type)
|
c.stmts_ending_with_expression(mut branch.stmts, c.expected_or_type)
|
||||||
} else {
|
} else {
|
||||||
|
@ -409,6 +411,7 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
first_iteration = false
|
first_iteration = false
|
||||||
if has_return := c.has_return(branch.stmts) {
|
if has_return := c.has_return(branch.stmts) {
|
||||||
if has_return {
|
if has_return {
|
||||||
|
|
|
@ -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]()
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue