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:
parent
785546f277
commit
638805be63
@ -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)
|
||||
|
8
vlib/v/tests/option_unwrap_print_test.v
Normal file
8
vlib/v/tests/option_unwrap_print_test.v
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user