diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index c73d2a37c2..c419ef876f 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -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) diff --git a/vlib/v/tests/option_unwrap_print_test.v b/vlib/v/tests/option_unwrap_print_test.v new file mode 100644 index 0000000000..34fd05db0c --- /dev/null +++ b/vlib/v/tests/option_unwrap_print_test.v @@ -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 +}