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

cgen: fix alias of map delete (#15644)

This commit is contained in:
yuyi 2022-09-03 15:41:53 +08:00 committed by GitHub
parent 1ef95fdec6
commit a5aad6f791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -980,3 +980,16 @@ fn test_map_set_fixed_array_variable() {
println(m2)
assert '$m2' == "{'A': [1.1, 2.2]}"
}
type Map = map[int]int
fn test_alias_of_map_delete() {
mut m := Map(map[int]int{})
m[11] = 111
m[22] = 222
println(m)
m.delete(11)
println(m)
assert m.len == 1
assert m[22] == 222
}

View File

@ -832,8 +832,8 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
}
}
if left_sym.kind == .map && node.name == 'delete' {
left_info := left_sym.info as ast.Map
if final_left_sym.kind == .map && node.name == 'delete' {
left_info := final_left_sym.info as ast.Map
elem_type_str := g.typ(left_info.key_type)
g.write('map_delete(')
if left_type.has_flag(.shared_f) {