mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix panic caused by compile-time code within or block (#16602)
This commit is contained in:
parent
94dc3c1c36
commit
edfaa76b3e
@ -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.typ == ast.void_type {
|
||||||
if stmt.expr is ast.IfExpr {
|
if stmt.expr is ast.IfExpr {
|
||||||
for branch in stmt.expr.branches {
|
for branch in stmt.expr.branches {
|
||||||
|
if branch.stmts.len > 0 {
|
||||||
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
|
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
} else if stmt.expr is ast.MatchExpr {
|
} else if stmt.expr is ast.MatchExpr {
|
||||||
for branch in stmt.expr.branches {
|
for branch in stmt.expr.branches {
|
||||||
|
if branch.stmts.len > 0 {
|
||||||
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
|
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
expected_type_name := c.table.type_to_str(ret_type.clear_flag(.optional).clear_flag(.result))
|
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 {
|
match stmt.expr {
|
||||||
ast.IfExpr {
|
ast.IfExpr {
|
||||||
for branch in stmt.expr.branches {
|
for branch in stmt.expr.branches {
|
||||||
|
if branch.stmts.len > 0 {
|
||||||
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
|
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ast.MatchExpr {
|
ast.MatchExpr {
|
||||||
for branch in stmt.expr.branches {
|
for branch in stmt.expr.branches {
|
||||||
|
if branch.stmts.len > 0 {
|
||||||
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
|
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
if stmt.typ == ast.void_type {
|
if stmt.typ == ast.void_type {
|
||||||
return
|
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…
Reference in New Issue
Block a user