Skip to content

Commit edfaa76

Browse files
authored
checker: fix panic caused by compile-time code within or block (#16602)
1 parent 94dc3c1 commit edfaa76

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

vlib/v/checker/checker.v

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,12 +1049,16 @@ fn (mut c Checker) check_or_last_stmt(stmt ast.Stmt, ret_type ast.Type, expr_ret
10491049
if stmt.typ == ast.void_type {
10501050
if stmt.expr is ast.IfExpr {
10511051
for branch in stmt.expr.branches {
1052-
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
1052+
if branch.stmts.len > 0 {
1053+
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
1054+
}
10531055
}
10541056
return
10551057
} else if stmt.expr is ast.MatchExpr {
10561058
for branch in stmt.expr.branches {
1057-
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
1059+
if branch.stmts.len > 0 {
1060+
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
1061+
}
10581062
}
10591063
return
10601064
}
@@ -1090,12 +1094,16 @@ fn (mut c Checker) check_or_last_stmt(stmt ast.Stmt, ret_type ast.Type, expr_ret
10901094
match stmt.expr {
10911095
ast.IfExpr {
10921096
for branch in stmt.expr.branches {
1093-
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
1097+
if branch.stmts.len > 0 {
1098+
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
1099+
}
10941100
}
10951101
}
10961102
ast.MatchExpr {
10971103
for branch in stmt.expr.branches {
1098-
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
1104+
if branch.stmts.len > 0 {
1105+
c.check_or_last_stmt(branch.stmts.last(), ret_type, expr_return_type)
1106+
}
10991107
}
11001108
}
11011109
else {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn foo() ! {
2+
}
3+
4+
fn test_bar() {
5+
foo() or {
6+
$if linux {
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)