From a5aad6f791d2c41a7c14cf27dc1333ef14b24b40 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 3 Sep 2022 15:41:53 +0800 Subject: [PATCH] cgen: fix alias of map delete (#15644) --- vlib/builtin/map_test.v | 13 +++++++++++++ vlib/v/gen/c/fn.v | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/vlib/builtin/map_test.v b/vlib/builtin/map_test.v index b199a91fa2..de3ba7e705 100644 --- a/vlib/builtin/map_test.v +++ b/vlib/builtin/map_test.v @@ -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 +} diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index ccfd871abe..2906205c72 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -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) {