1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix accessing fields in propagated optional subexpressions (#10136)

This commit is contained in:
spaceface 2021-05-19 20:28:17 +02:00 committed by GitHub
parent be189e0059
commit 9ddf1ec327
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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')
}

View File

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