cgen: fix option unwrapping on heap var (#23489)

This commit is contained in:
Felipe Pena 2025-01-16 18:04:57 -03:00 committed by GitHub
parent f9106a86fb
commit d23e70f546
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View file

@ -5115,8 +5115,13 @@ fn (mut g Gen) ident(node ast.Ident) {
} }
} }
} }
if node.obj.ct_type_var != .smartcast && node.obj.is_unwrapped { if i == 0 && node.obj.ct_type_var != .smartcast && node.obj.is_unwrapped {
g.write('.data') dot := if !node.obj.orig_type.is_ptr() && obj_sym.is_heap() {
'->'
} else {
'.'
}
g.write('${dot}data')
} }
g.write(')') g.write(')')
} }

View 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
}
}