diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 43fadb1e6f..2a2adb9a3c 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -191,7 +191,8 @@ fn (mut f Fmt) stmt(node ast.Stmt) { } ast.CompIf { inversion := if it.is_not { '!' } else { '' } - f.writeln('\$if ${inversion}${it.val} {') + is_opt := if it.is_opt { ' ?' } else { '' } + f.writeln('\$if ${inversion}${it.val}${is_opt} {') f.stmts(it.stmts) if it.has_else { f.writeln('} \$else {') @@ -306,6 +307,7 @@ fn (mut f Fmt) stmt(node ast.Stmt) { f.write(' = ') f.expr(it.expr) } + f.writeln('') } ast.GoStmt { f.write('go ') diff --git a/vlib/v/fmt/tests/conditional_compilation_keep.vv b/vlib/v/fmt/tests/conditional_compilation_keep.vv index fc42a75497..3d7e1d236c 100644 --- a/vlib/v/fmt/tests/conditional_compilation_keep.vv +++ b/vlib/v/fmt/tests/conditional_compilation_keep.vv @@ -1,3 +1,4 @@ +// __global g_my_global_variable int fn main() { $if tinyc { println('This will be compiled only when the compiler is tcc') @@ -11,4 +12,8 @@ fn main() { } $else { println('This part is for linux only.') } + // + $if network ? { + println('This will be run, only when the program is compiled with `-d network`') + } }