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

checker: disallow mut keyword in right-hand side of assignment (#12318)

This commit is contained in:
Lucas Jenß 2021-10-29 11:03:05 +02:00 committed by GitHub
parent a32dae335a
commit f801ef5e17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -3717,6 +3717,11 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
right.pos)
}
}
if right is ast.Ident {
if right.is_mut {
c.error('unexpected `mut` on right-hand side of assignment', right.mut_pos)
}
}
}
if node.left.len != right_len {
if right_first is ast.CallExpr {

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/right_hand_side_mut.vv:4:19: error: unexpected `mut` on right-hand side of assignment
2 | mut flubbel := 123
3 | mut wubbel := 234
4 | _, _ := flubbel, mut wubbel
| ~~~
5 | print(wubbel)
6 | }

View File

@ -0,0 +1,6 @@
fn main() {
mut flubbel := 123
mut wubbel := 234
_, _ := flubbel, mut wubbel
print(wubbel)
}