diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 7688fff78d117f..94c38ba25fbb9c 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5115,8 +5115,13 @@ fn (mut g Gen) ident(node ast.Ident) { } } } - if node.obj.ct_type_var != .smartcast && node.obj.is_unwrapped { - g.write('.data') + if i == 0 && node.obj.ct_type_var != .smartcast && node.obj.is_unwrapped { + dot := if !node.obj.orig_type.is_ptr() && obj_sym.is_heap() { + '->' + } else { + '.' + } + g.write('${dot}data') } g.write(')') } diff --git a/vlib/v/tests/options/option_heap_var_test.v b/vlib/v/tests/options/option_heap_var_test.v new file mode 100644 index 00000000000000..c4b879653431dc --- /dev/null +++ b/vlib/v/tests/options/option_heap_var_test.v @@ -0,0 +1,21 @@ +@[heap] +struct Foo { + a int +} + +struct EdgeService { + foo Foo +} + +fn t[S](s S) { +} + +fn test_main() { + mut svc := ?EdgeService(EdgeService{}) + if svc != none { + t(svc) + assert true + } else { + assert false + } +}