From b83dd86d651d2109be69b0a847d2eff2afebe905 Mon Sep 17 00:00:00 2001 From: StunxFS <56417208+StunxFS@users.noreply.github.com> Date: Fri, 26 Aug 2022 00:08:05 -0400 Subject: [PATCH] checker: check error for simple assignment with dumping of multireturn value (#15512) --- vlib/v/checker/assign.v | 2 +- vlib/v/checker/tests/assign_with_dump_multireturn_value.out | 6 ++++++ vlib/v/checker/tests/assign_with_dump_multireturn_value.vv | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 vlib/v/checker/tests/assign_with_dump_multireturn_value.out create mode 100644 vlib/v/checker/tests/assign_with_dump_multireturn_value.vv diff --git a/vlib/v/checker/assign.v b/vlib/v/checker/assign.v index ea399fb60..1987f3485 100644 --- a/vlib/v/checker/assign.v +++ b/vlib/v/checker/assign.v @@ -17,7 +17,7 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) { mut right_len := node.right.len mut right_type0 := ast.void_type for i, mut right in node.right { - if right in [ast.CallExpr, ast.IfExpr, ast.LockExpr, ast.MatchExpr] { + if right in [ast.CallExpr, ast.IfExpr, ast.LockExpr, ast.MatchExpr, ast.DumpExpr] { if right in [ast.IfExpr, ast.MatchExpr] && node.left.len == node.right.len && !is_decl && node.left[i] in [ast.Ident, ast.SelectorExpr] && !node.left[i].is_blank_ident() { c.expected_type = c.expr(node.left[i]) diff --git a/vlib/v/checker/tests/assign_with_dump_multireturn_value.out b/vlib/v/checker/tests/assign_with_dump_multireturn_value.out new file mode 100644 index 000000000..88dd6c238 --- /dev/null +++ b/vlib/v/checker/tests/assign_with_dump_multireturn_value.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/assign_with_dump_multireturn_value.vv:5:3: error: assignment mismatch: 1 variable(s) 2 value(s) + 3 | } + 4 | + 5 | x := dump(two_returns()) + | ~~ + 6 | println(x) diff --git a/vlib/v/checker/tests/assign_with_dump_multireturn_value.vv b/vlib/v/checker/tests/assign_with_dump_multireturn_value.vv new file mode 100644 index 000000000..e687cd657 --- /dev/null +++ b/vlib/v/checker/tests/assign_with_dump_multireturn_value.vv @@ -0,0 +1,6 @@ +fn two_returns() (string, string) { + return 'hello', 'world' +} + +x := dump(two_returns()) +println(x) -- 2.30.2