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

checker: fix parenexpr checking on assignment (#17593)

This commit is contained in:
Felipe Pena 2023-03-11 09:56:47 -03:00 committed by GitHub
parent dc24df9510
commit ddcc22fe08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 6 deletions

View File

@ -80,10 +80,18 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
c.error('assignment mismatch: ${node.left.len} variable(s) but `${right_first.name}()` returns ${right_len} value(s)',
node.pos)
} else if right_first is ast.ParExpr {
if right_first.expr is ast.CallExpr {
if right_first.expr.return_type == ast.void_type {
c.error('assignment mismatch: expected ${node.left.len} value(s) but `${right_first.expr.name}()` returns ${right_len} value(s)',
node.pos)
mut right_next := right_first
for {
if right_next.expr is ast.CallExpr {
if (right_next.expr as ast.CallExpr).return_type == ast.void_type {
c.error('assignment mismatch: expected ${node.left.len} value(s) but `${(right_next.expr as ast.CallExpr).name}()` returns ${right_len} value(s)',
node.pos)
}
break
} else if right_next.expr is ast.ParExpr {
right_next = right_next.expr as ast.ParExpr
} else {
break
}
}
} else {

View File

@ -1,3 +1,12 @@
vlib/v/checker/tests/par_expr_assign_void_right_type_err.vv:1:6: warning: redundant parentheses are used
1 | _ := ((((print(10)))))
| ~~~~~~~~~~~~~~~~~
vlib/v/checker/tests/par_expr_assign_void_right_type_err.vv:1:7: warning: redundant parentheses are used
1 | _ := ((((print(10)))))
| ~~~~~~~~~~~~~~~
vlib/v/checker/tests/par_expr_assign_void_right_type_err.vv:1:8: warning: redundant parentheses are used
1 | _ := ((((print(10)))))
| ~~~~~~~~~~~~~
vlib/v/checker/tests/par_expr_assign_void_right_type_err.vv:1:3: error: assignment mismatch: expected 1 value(s) but `print()` returns 0 value(s)
1 | _ := (print(10))
1 | _ := ((((print(10)))))
| ~~

View File

@ -1 +1 @@
_ := (print(10))
_ := ((((print(10)))))