Skip to content

Commit 5300441

Browse files
authored
cgen: fix alias of map clone() (fix #18384) (#18386)
1 parent 01b2048 commit 5300441

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

vlib/v/gen/c/fn.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
12771277
g.get_free_method(rec_type)
12781278
}
12791279
mut has_cast := false
1280-
if left_sym.kind == .map && node.name in ['clone', 'move'] {
1280+
if final_left_sym.kind == .map && node.name in ['clone', 'move'] {
12811281
receiver_type_name = 'map'
12821282
}
12831283
if final_left_sym.kind == .array && !(left_sym.kind == .alias && left_sym.has_method(node.name))

vlib/v/tests/alias_map_clone_test.v

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
type Fields = map[string]string
2+
3+
fn test_alias_map_clone() {
4+
f := Fields({
5+
's': 'a'
6+
})
7+
8+
s := f.clone()
9+
println(s)
10+
assert s == {
11+
's': 'a'
12+
}
13+
}

0 commit comments

Comments
 (0)