Skip to content

Commit

Permalink
parser: fix formatting comptime if expr script (v fmt no longer eats …
Browse files Browse the repository at this point in the history
…the body of top level `$if xyz ? {}`) (#19044)
  • Loading branch information
yuyi98 committed Aug 3, 2023
1 parent b556f13 commit 5ec7ee9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions vlib/v/fmt/tests/comptime_if_expr_script_keep.vv
@@ -0,0 +1,6 @@
mut pre_built_str := ''
$if prebuilt ? {
the_date := if $env('DATE') != '' { $env('DATE') } else { '##DATE##' }
pre_built_str = '[pre-built binary release (${the_date})]\n'
}
dump(pre_built_str)
2 changes: 1 addition & 1 deletion vlib/v/parser/parser.v
Expand Up @@ -764,7 +764,7 @@ fn (mut p Parser) top_stmt() ast.Stmt {
expr: if_expr
pos: if_expr.pos
}
if comptime_if_expr_contains_top_stmt(if_expr) {
if p.pref.is_fmt || comptime_if_expr_contains_top_stmt(if_expr) {
return cur_stmt
} else {
return p.other_stmts(cur_stmt)
Expand Down

0 comments on commit 5ec7ee9

Please sign in to comment.