mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
checker: fix panic caused by compile-time code within or block (#16602)
This commit is contained in:
parent
94dc3c1c36
commit
edfaa76b3e
2 changed files with 21 additions and 4 deletions
|
@ -1049,13 +1049,17 @@ fn (mut c Checker) check_or_last_stmt(stmt ast.Stmt, ret_type ast.Type, expr_ret
|
|||
if stmt.typ == ast.void_type {
|
||||
if stmt.expr is ast.IfExpr {
|
||||
for branch in stmt.expr.branches {
|
||||
if branch.stmts.len > 0 {
|
||||
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
|
||||
}
|
||||
}
|
||||
return
|
||||
} else if stmt.expr is ast.MatchExpr {
|
||||
for branch in stmt.expr.branches {
|
||||
if branch.stmts.len > 0 {
|
||||
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
expected_type_name := c.table.type_to_str(ret_type.clear_flag(.optional).clear_flag(.result))
|
||||
|
@ -1090,14 +1094,18 @@ fn (mut c Checker) check_or_last_stmt(stmt ast.Stmt, ret_type ast.Type, expr_ret
|
|||
match stmt.expr {
|
||||
ast.IfExpr {
|
||||
for branch in stmt.expr.branches {
|
||||
if branch.stmts.len > 0 {
|
||||
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
|
||||
}
|
||||
}
|
||||
}
|
||||
ast.MatchExpr {
|
||||
for branch in stmt.expr.branches {
|
||||
if branch.stmts.len > 0 {
|
||||
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if stmt.typ == ast.void_type {
|
||||
return
|
||||
|
|
9
vlib/v/tests/or_expr_with_comptime_test.v
Normal file
9
vlib/v/tests/or_expr_with_comptime_test.v
Normal file
|
@ -0,0 +1,9 @@
|
|||
fn foo() ! {
|
||||
}
|
||||
|
||||
fn test_bar() {
|
||||
foo() or {
|
||||
$if linux {
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue