mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix map['xxx']() error (#7342)
This commit is contained in:
parent
239a8c8aa3
commit
e40e1500a8
|
@ -3765,14 +3765,14 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
|
||||||
if needs_clone {
|
if needs_clone {
|
||||||
g.write('/*2*/string_clone(')
|
g.write('/*2*/string_clone(')
|
||||||
}
|
}
|
||||||
if is_direct_array_access {
|
if g.is_fn_index_call {
|
||||||
g.write('(($array_ptr_type_str)')
|
|
||||||
} else if g.is_fn_index_call {
|
|
||||||
if elem_typ.info is table.FnType {
|
if elem_typ.info is table.FnType {
|
||||||
g.write('((')
|
g.write('((')
|
||||||
g.write_fn_ptr_decl(&elem_typ.info, '')
|
g.write_fn_ptr_decl(&elem_typ.info, '')
|
||||||
g.write(')(*($array_ptr_type_str)/*ee elem_typ */array_get(')
|
g.write(')(*($array_ptr_type_str)/*ee elem_typ */array_get(')
|
||||||
}
|
}
|
||||||
|
} else if is_direct_array_access {
|
||||||
|
g.write('(($array_ptr_type_str)')
|
||||||
} else {
|
} else {
|
||||||
g.write('(*($array_ptr_type_str)/*ee elem_typ */array_get(')
|
g.write('(*($array_ptr_type_str)/*ee elem_typ */array_get(')
|
||||||
if left_is_ptr && !node.left_type.has_flag(.shared_f) {
|
if left_is_ptr && !node.left_type.has_flag(.shared_f) {
|
||||||
|
@ -3857,7 +3857,13 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
|
||||||
g.write(', &($elem_type_str[]){ $zero }))')
|
g.write(', &($elem_type_str[]){ $zero }))')
|
||||||
} else {
|
} else {
|
||||||
zero := g.type_default(info.value_type)
|
zero := g.type_default(info.value_type)
|
||||||
if elem_typ.kind == .function {
|
if g.is_fn_index_call {
|
||||||
|
if elem_typ.info is table.FnType {
|
||||||
|
g.write('((')
|
||||||
|
g.write_fn_ptr_decl(&elem_typ.info, '')
|
||||||
|
g.write(')(*(voidptr*)map_get(')
|
||||||
|
}
|
||||||
|
} else if elem_typ.kind == .function {
|
||||||
g.write('(*(voidptr*)map_get(')
|
g.write('(*(voidptr*)map_get(')
|
||||||
} else {
|
} else {
|
||||||
g.write('(*($elem_type_str*)map_get(')
|
g.write('(*($elem_type_str*)map_get(')
|
||||||
|
@ -3875,7 +3881,9 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
|
||||||
}
|
}
|
||||||
g.write(', ')
|
g.write(', ')
|
||||||
g.expr(node.index)
|
g.expr(node.index)
|
||||||
if elem_typ.kind == .function {
|
if g.is_fn_index_call {
|
||||||
|
g.write(', &(voidptr[]){ $zero })))')
|
||||||
|
} else if elem_typ.kind == .function {
|
||||||
g.write(', &(voidptr[]){ $zero }))')
|
g.write(', &(voidptr[]){ $zero }))')
|
||||||
} else {
|
} else {
|
||||||
g.write(', &($elem_type_str[]){ $zero }))')
|
g.write(', &($elem_type_str[]){ $zero }))')
|
||||||
|
|
|
@ -13,5 +13,17 @@ fn test_fn_array_direct_call() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println(fs.array_of_fn[0](1, &Placeholder{name: 'Bob'}, 'Builder'))
|
||||||
assert fs.array_of_fn[0](1, &Placeholder{name: 'Bob'}, 'Builder') == false
|
assert fs.array_of_fn[0](1, &Placeholder{name: 'Bob'}, 'Builder') == false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_fn_map_direct_call() {
|
||||||
|
a := {
|
||||||
|
'aaa': fn()string {return 'aaa'},
|
||||||
|
'bbb': fn()string {return 'bbb'},
|
||||||
|
}
|
||||||
|
println(a['aaa']())
|
||||||
|
println(a['bbb']())
|
||||||
|
assert a['aaa']() == 'aaa'
|
||||||
|
assert a['bbb']() == 'bbb'
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user