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 (fix #15972) (#16036)

This commit is contained in:
shove 2022-10-11 21:33:19 +08:00 committed by GitHub
parent 05fc7d3a72
commit 4c0ea67137
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -3760,7 +3760,7 @@ fn (mut g Gen) unlock_locks() {
fn (mut g Gen) map_init(node ast.MapInit) {
unwrap_key_typ := g.unwrap_generic(node.key_type)
unwrap_val_typ := g.unwrap_generic(node.value_type)
unwrap_val_typ := g.unwrap_generic(node.value_type).clear_flag(.optional).clear_flag(.result)
key_typ_str := g.typ(unwrap_key_typ)
value_typ_str := g.typ(unwrap_val_typ)
value_sym := g.table.sym(unwrap_val_typ)

View File

@ -378,7 +378,7 @@ 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)
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

@ -0,0 +1,11 @@
import os
struct AdbDevice {
opts map[string]?string
}
fn test_map_value_with_optional_result() {
// avoid warnings
_ := os.max_path_len
assert true
}