mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix shared map delete (#15431)
This commit is contained in:
parent
26986eb2f8
commit
8be85e7590
@ -827,11 +827,19 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
|
||||
left_info := left_sym.info as ast.Map
|
||||
elem_type_str := g.typ(left_info.key_type)
|
||||
g.write('map_delete(')
|
||||
if left_type.is_ptr() {
|
||||
if left_type.has_flag(.shared_f) {
|
||||
if left_type.is_ptr() {
|
||||
g.write('&')
|
||||
}
|
||||
g.expr(node.left)
|
||||
g.write('->val')
|
||||
} else {
|
||||
g.write('&')
|
||||
g.expr(node.left)
|
||||
if left_type.is_ptr() {
|
||||
g.expr(node.left)
|
||||
} else {
|
||||
g.write('&')
|
||||
g.expr(node.left)
|
||||
}
|
||||
}
|
||||
g.write(', &($elem_type_str[]){')
|
||||
g.expr(node.args[0].expr)
|
||||
@ -839,11 +847,19 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
|
||||
return
|
||||
} else if left_sym.kind == .array && node.name == 'delete' {
|
||||
g.write('array_delete(')
|
||||
if left_type.is_ptr() {
|
||||
if left_type.has_flag(.shared_f) {
|
||||
if left_type.is_ptr() {
|
||||
g.write('&')
|
||||
}
|
||||
g.expr(node.left)
|
||||
g.write('->val')
|
||||
} else {
|
||||
g.write('&')
|
||||
g.expr(node.left)
|
||||
if left_type.is_ptr() {
|
||||
g.expr(node.left)
|
||||
} else {
|
||||
g.write('&')
|
||||
g.expr(node.left)
|
||||
}
|
||||
}
|
||||
g.write(', ')
|
||||
g.expr(node.args[0].expr)
|
||||
|
14
vlib/v/tests/shared_map_delete_test.v
Normal file
14
vlib/v/tests/shared_map_delete_test.v
Normal file
@ -0,0 +1,14 @@
|
||||
fn test_shared_map_delete() {
|
||||
shared store := map[string]int{}
|
||||
lock store {
|
||||
store['abc'] = 5
|
||||
store['xyz'] = 10
|
||||
}
|
||||
|
||||
lock store {
|
||||
assert store.len == 2
|
||||
store.delete('abc')
|
||||
assert store.len == 1
|
||||
assert store['xyz'] == 10
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user