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

ast: fix error for complex map operating (#14204)

This commit is contained in:
yuyi 2022-04-28 18:20:56 +08:00 committed by GitHub
parent a225b25117
commit c802688690
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -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)
}
}
}

View File

@ -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
}