From c802688690c0cf98e2182b16dbc7a7dd683281a7 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 28 Apr 2022 18:20:56 +0800 Subject: [PATCH] ast: fix error for complex map operating (#14204) --- vlib/v/ast/ast.v | 4 ++++ vlib/v/tests/complex_map_op_test.v | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 vlib/v/tests/complex_map_op_test.v diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 72a067d18f..78c1e97c51 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -2074,6 +2074,10 @@ pub fn (mut lx IndexExpr) recursive_mapset_is_setter(val bool) { if lx.left.is_map { lx.left.recursive_mapset_is_setter(val) } + } else if mut lx.left is SelectorExpr { + if mut lx.left.expr is IndexExpr { + lx.left.expr.recursive_mapset_is_setter(val) + } } } diff --git a/vlib/v/tests/complex_map_op_test.v b/vlib/v/tests/complex_map_op_test.v new file mode 100644 index 0000000000..4e9947abf4 --- /dev/null +++ b/vlib/v/tests/complex_map_op_test.v @@ -0,0 +1,24 @@ +fn test_complex_map_op() { + mut test_map := map[string]Point_map{} + + test_map['test1'].points['point3'] << Point{10, 20} + test_map['test2'].points['point4'] << Point{50, 60} + + println(test_map) + assert test_map.len == 2 + assert Point{10, 20} in test_map['test1'].points['point3'] + assert Point{50, 60} in test_map['test2'].points['point4'] + assert Point{10, 20} !in test_map['test2'].points['point4'] + assert Point{1, 2} !in test_map['test1'].points['point3'] +} + +struct Point { +mut: + x int + y int +} + +struct Point_map { +mut: + points map[string][]Point +}