Skip to content

Commit

Permalink
checker: fix comptime ident checking on defer stmt (fix #20719) (#20723)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Feb 4, 2024
1 parent abd2b64 commit ec7e058
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/v/checker/checker.v
Expand Up @@ -2036,7 +2036,8 @@ fn (mut c Checker) stmt(mut node ast.Stmt) {
for i, ident in node.defer_vars {
mut id := ident
if mut id.info is ast.IdentVar {
if id.comptime && id.name in ast.valid_comptime_not_user_defined {
if id.comptime && (id.tok_kind == .question
|| id.name in ast.valid_comptime_not_user_defined) {
node.defer_vars[i] = ast.Ident{
scope: unsafe { nil }
name: ''
Expand Down
9 changes: 9 additions & 0 deletions vlib/v/tests/defer_if_comptime_test.v
@@ -0,0 +1,9 @@
fn test_main() {
defer {
$if foo ? {
assert false
} $else {
assert true
}
}
}

0 comments on commit ec7e058

Please sign in to comment.