mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
cgen: fix option unwrapping on heap var (#23489)
This commit is contained in:
parent
f9106a86fb
commit
d23e70f546
2 changed files with 28 additions and 2 deletions
|
@ -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(')')
|
||||
}
|
||||
|
|
21
vlib/v/tests/options/option_heap_var_test.v
Normal file
21
vlib/v/tests/options/option_heap_var_test.v
Normal file
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue