Skip to content

Commit d23e70f

Browse files
authored
cgen: fix option unwrapping on heap var (#23489)
1 parent f9106a8 commit d23e70f

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

vlib/v/gen/c/cgen.v

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5115,8 +5115,13 @@ fn (mut g Gen) ident(node ast.Ident) {
51155115
}
51165116
}
51175117
}
5118-
if node.obj.ct_type_var != .smartcast && node.obj.is_unwrapped {
5119-
g.write('.data')
5118+
if i == 0 && node.obj.ct_type_var != .smartcast && node.obj.is_unwrapped {
5119+
dot := if !node.obj.orig_type.is_ptr() && obj_sym.is_heap() {
5120+
'->'
5121+
} else {
5122+
'.'
5123+
}
5124+
g.write('${dot}data')
51205125
}
51215126
g.write(')')
51225127
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@[heap]
2+
struct Foo {
3+
a int
4+
}
5+
6+
struct EdgeService {
7+
foo Foo
8+
}
9+
10+
fn t[S](s S) {
11+
}
12+
13+
fn test_main() {
14+
mut svc := ?EdgeService(EdgeService{})
15+
if svc != none {
16+
t(svc)
17+
assert true
18+
} else {
19+
assert false
20+
}
21+
}

0 commit comments

Comments
 (0)