diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 6c1bb41b38..3daeb2e313 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -462,7 +462,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) { g.write('\n $cur_line $tmp_opt /*U*/') } else { if !g.inside_const { - g.write('\n $cur_line *($unwrapped_styp*)${tmp_opt}.data') + g.write('\n $cur_line (*($unwrapped_styp*)${tmp_opt}.data)') } else { g.write('\n $cur_line $tmp_opt') } diff --git a/vlib/v/tests/option_2_test.v b/vlib/v/tests/option_2_test.v index 40db899fa4..ebb9c7635c 100644 --- a/vlib/v/tests/option_2_test.v +++ b/vlib/v/tests/option_2_test.v @@ -56,3 +56,11 @@ fn test_nested_opt() { a := f(f(f(-3) or { -7 }) or { 4 }) or { 17 } assert a == 4 } + +fn foo() ?string { + return 'hi' +} + +fn test_opt_subexp_field() ? { + assert foo() ?.len == 2 +}