Skip to content

Commit

Permalink
cgen: fix option unwrapping on heap var (vlang#23489)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Jan 16, 2025
1 parent f9106a8 commit d23e70f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 7 additions & 2 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -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(')')
}
Expand Down
21 changes: 21 additions & 0 deletions vlib/v/tests/options/option_heap_var_test.v
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit d23e70f

Please sign in to comment.