cgen: fix or_block in for declaration (#10317)

pull/10336/head
yuyi 2021-06-03 06:18:52 +08:00 committed by GitHub
parent b28def7c11
commit b0bafa6376
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -5912,6 +5912,9 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty
g.indent--
} else {
g.stmts(stmts)
if stmts.len > 0 && stmts[or_block.stmts.len - 1] is ast.ExprStmt {
g.writeln(';')
}
}
} else if or_block.kind == .propagate {
if g.file.mod.name == 'main' && (isnil(g.fn_decl) || g.fn_decl.is_main) {
@ -5942,7 +5945,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty
}
}
}
g.write('}')
g.writeln('}')
}
// `a in [1,2,3]` => `a == 1 || a == 2 || a == 3`

View File

@ -0,0 +1,8 @@
import os
fn test_for_in_optional() {
for d in os.read_lines(@FILE) or { panic('not found') } {
println(d)
}
assert true
}