cgen: fix accessing fields in propagated optional subexpressions (#10136)
parent
be189e0059
commit
9ddf1ec327
|
@ -462,7 +462,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
|
|||
g.write('\n $cur_line $tmp_opt /*U*/')
|
||||
} else {
|
||||
if !g.inside_const {
|
||||
g.write('\n $cur_line *($unwrapped_styp*)${tmp_opt}.data')
|
||||
g.write('\n $cur_line (*($unwrapped_styp*)${tmp_opt}.data)')
|
||||
} else {
|
||||
g.write('\n $cur_line $tmp_opt')
|
||||
}
|
||||
|
|
|
@ -56,3 +56,11 @@ fn test_nested_opt() {
|
|||
a := f(f(f(-3) or { -7 }) or { 4 }) or { 17 }
|
||||
assert a == 4
|
||||
}
|
||||
|
||||
fn foo() ?string {
|
||||
return 'hi'
|
||||
}
|
||||
|
||||
fn test_opt_subexp_field() ? {
|
||||
assert foo() ?.len == 2
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue