From 5300441c09ef7bd6c6c7cc21ffa9dacf02e7cc66 Mon Sep 17 00:00:00 2001 From: yuyi Date: Fri, 9 Jun 2023 17:58:38 +0800 Subject: [PATCH] cgen: fix alias of map clone() (fix #18384) (#18386) --- vlib/v/gen/c/fn.v | 2 +- vlib/v/tests/alias_map_clone_test.v | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/alias_map_clone_test.v diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index f4f5e19146..1fca275b26 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -1277,7 +1277,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) { g.get_free_method(rec_type) } mut has_cast := false - if left_sym.kind == .map && node.name in ['clone', 'move'] { + if final_left_sym.kind == .map && node.name in ['clone', 'move'] { receiver_type_name = 'map' } if final_left_sym.kind == .array && !(left_sym.kind == .alias && left_sym.has_method(node.name)) diff --git a/vlib/v/tests/alias_map_clone_test.v b/vlib/v/tests/alias_map_clone_test.v new file mode 100644 index 0000000000..781e047c53 --- /dev/null +++ b/vlib/v/tests/alias_map_clone_test.v @@ -0,0 +1,13 @@ +type Fields = map[string]string + +fn test_alias_map_clone() { + f := Fields({ + 's': 'a' + }) + + s := f.clone() + println(s) + assert s == { + 's': 'a' + } +}