1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vfmt: fix eating ? in $if x ? {}, missing newline in __global ...

This commit is contained in:
Delyan Angelov 2020-05-01 12:25:18 +03:00
parent 59525c8c93
commit 35f56bc4f0
2 changed files with 8 additions and 1 deletions

View File

@ -191,7 +191,8 @@ fn (mut f Fmt) stmt(node ast.Stmt) {
} }
ast.CompIf { ast.CompIf {
inversion := if it.is_not { '!' } else { '' } 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) f.stmts(it.stmts)
if it.has_else { if it.has_else {
f.writeln('} \$else {') f.writeln('} \$else {')
@ -306,6 +307,7 @@ fn (mut f Fmt) stmt(node ast.Stmt) {
f.write(' = ') f.write(' = ')
f.expr(it.expr) f.expr(it.expr)
} }
f.writeln('')
} }
ast.GoStmt { ast.GoStmt {
f.write('go ') f.write('go ')

View File

@ -1,3 +1,4 @@
// __global g_my_global_variable int
fn main() { fn main() {
$if tinyc { $if tinyc {
println('This will be compiled only when the compiler is tcc') println('This will be compiled only when the compiler is tcc')
@ -11,4 +12,8 @@ fn main() {
} $else { } $else {
println('This part is for linux only.') println('This part is for linux only.')
} }
//
$if network ? {
println('This will be run, only when the program is compiled with `-d network`')
}
} }