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

cgen: fix map with optional or result on return (#16044)

This commit is contained in:
shove 2022-10-12 12:54:29 +08:00 committed by GitHub
parent 12d3664a09
commit 9569c0504c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -378,7 +378,11 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) {
elem_type_str := if elem_sym.kind == .function {
'voidptr'
} else {
g.typ(elem_type.clear_flag(.optional).clear_flag(.result))
if g.inside_return {
g.typ(elem_type)
} else {
g.typ(elem_type.clear_flag(.optional).clear_flag(.result))
}
}
get_and_set_types := elem_sym.kind in [.struct_, .map]
if g.is_assign_lhs && !g.is_arraymap_set && !get_and_set_types {

View File

@ -9,3 +9,7 @@ fn test_map_value_with_optional_result() {
_ := os.max_path_len
assert true
}
fn foo(arg map[string]?string) ?string {
return arg['akey']
}