checker: fix error of map selector assign (#12902)

pull/12908/head
yuyi 2021-12-20 14:09:15 +08:00 committed by GitHub
parent d07975335d
commit 7c85c2ab1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -300,6 +300,13 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
c.error('non-name on the left side of `:=`', left.pos)
}
}
ast.SelectorExpr {
if mut left.expr is ast.IndexExpr {
if left.expr.is_map {
left.expr.is_setter = true
}
}
}
else {
if mut left is ast.IndexExpr {
// eprintln('>>> left.is_setter: ${left.is_setter:10} | left.is_map: ${left.is_map:10} | left.is_array: ${left.is_array:10}')

View File

@ -0,0 +1,11 @@
struct Test {
mut:
data int
}
fn test_map_selector_assign() {
mut m := map[int]Test{}
m[0].data = 1
println(m[0].data)
assert m[0].data == 1
}