1
0
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:
Felipe Pena 2022-12-06 04:26:04 -03:00 committed by GitHub
parent 94dc3c1c36
commit edfaa76b3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View File

@ -1049,12 +1049,16 @@ 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 {
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
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 {
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
if branch.stmts.len > 0 {
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
}
}
return
}
@ -1090,12 +1094,16 @@ 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 {
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
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 {
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
if branch.stmts.len > 0 {
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
}
}
}
else {

View File

@ -0,0 +1,9 @@
fn foo() ! {
}
fn test_bar() {
foo() or {
$if linux {
}
}
}