mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix nested map of fn call (#18142)
This commit is contained in:
parent
e2e6c9660c
commit
89f3288fb0
@ -474,6 +474,7 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) {
|
||||
}
|
||||
tmp_opt := if gen_or { g.new_tmp_var() } else { '' }
|
||||
tmp_opt_ptr := if gen_or { g.new_tmp_var() } else { '' }
|
||||
mut is_fn_last_index_call := false
|
||||
if gen_or {
|
||||
g.write('${elem_type_str}* ${tmp_opt_ptr} = (${elem_type_str}*)(map_get_check(')
|
||||
} else {
|
||||
@ -482,6 +483,8 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) {
|
||||
g.write('((')
|
||||
g.write_fn_ptr_decl(&elem_sym.info, '')
|
||||
g.write(')(*(voidptr*)map_get(')
|
||||
is_fn_last_index_call = true
|
||||
g.is_fn_index_call = false
|
||||
}
|
||||
} else {
|
||||
g.write('(*(${elem_type_str}*)map_get(')
|
||||
@ -506,7 +509,7 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) {
|
||||
g.write('}')
|
||||
if gen_or {
|
||||
g.write('))')
|
||||
} else if g.is_fn_index_call {
|
||||
} else if is_fn_last_index_call {
|
||||
g.write(', &(voidptr[]){ ${zero} })))')
|
||||
} else {
|
||||
g.write(', &(${elem_type_str}[]){ ${zero} }))')
|
||||
|
9
vlib/v/tests/nested_map_of_fn_call_test.v
Normal file
9
vlib/v/tests/nested_map_of_fn_call_test.v
Normal file
@ -0,0 +1,9 @@
|
||||
fn test_nested_map_of_fn_call() {
|
||||
mut a := map[string]map[string]fn () int{}
|
||||
a['a']['a'] = fn () int {
|
||||
return 0
|
||||
}
|
||||
b := a['a']['a']()
|
||||
println(b)
|
||||
assert b == 0
|
||||
}
|
Loading…
Reference in New Issue
Block a user