From f801ef5e1733d53d011b6456fadb254af5caceb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Jen=C3=9F?= Date: Fri, 29 Oct 2021 11:03:05 +0200 Subject: [PATCH] checker: disallow `mut` keyword in right-hand side of assignment (#12318) --- vlib/v/checker/checker.v | 5 +++++ vlib/v/checker/tests/right_hand_side_mut.out | 7 +++++++ vlib/v/checker/tests/right_hand_side_mut.vv | 6 ++++++ 3 files changed, 18 insertions(+) create mode 100644 vlib/v/checker/tests/right_hand_side_mut.out create mode 100644 vlib/v/checker/tests/right_hand_side_mut.vv diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 12ebdb888a..f4fe75e070 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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 { diff --git a/vlib/v/checker/tests/right_hand_side_mut.out b/vlib/v/checker/tests/right_hand_side_mut.out new file mode 100644 index 0000000000..c52488c03a --- /dev/null +++ b/vlib/v/checker/tests/right_hand_side_mut.out @@ -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 | } diff --git a/vlib/v/checker/tests/right_hand_side_mut.vv b/vlib/v/checker/tests/right_hand_side_mut.vv new file mode 100644 index 0000000000..919efd63ce --- /dev/null +++ b/vlib/v/checker/tests/right_hand_side_mut.vv @@ -0,0 +1,6 @@ +fn main() { + mut flubbel := 123 + mut wubbel := 234 + _, _ := flubbel, mut wubbel + print(wubbel) +}