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

cgen: fix code for unwrap option on print (#17545)

This commit is contained in:
Felipe Pena 2023-03-08 16:55:19 -03:00 committed by GitHub
parent 785546f277
commit 638805be63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -1482,6 +1482,10 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
typ = cast_sym.info.types[g.aggregate_type_idx]
}
}
// handling println( var or { ... })
if typ.has_flag(.option) && expr.or_expr.kind != .absent {
typ = typ.clear_flag(.option)
}
}
}
g.gen_expr_to_string(expr, typ)

View File

@ -0,0 +1,8 @@
fn test_main() {
var := ?int(none)
println(var or { 100 })
println(var or { 100 })
assert dump(var or { 100 }) == 100
assert dump(var or { 100 }) == 100
assert true
}