mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add a checker error for fn calls on left side of an assignment (#5993)
This commit is contained in:
parent
7b630f0350
commit
4500e7131e
@ -1619,6 +1619,10 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
|
||||
//
|
||||
is_decl := assign_stmt.op == .decl_assign
|
||||
for i, left in assign_stmt.left {
|
||||
if left is ast.CallExpr {
|
||||
c.error('cannot call function `${left.name}()` on the left side of an assignment',
|
||||
left.pos)
|
||||
}
|
||||
is_blank_ident := left.is_blank_ident()
|
||||
mut left_type := table.void_type
|
||||
if !is_decl && !is_blank_ident {
|
||||
|
6
vlib/v/checker/tests/assign_fn_call_on_left_side_err.out
Normal file
6
vlib/v/checker/tests/assign_fn_call_on_left_side_err.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/assign_fn_call_on_left_side_err.v:6:2: error: cannot call function `foo()` on the left side of an assignment
|
||||
4 |
|
||||
5 | fn main() {
|
||||
6 | foo('s') = 1
|
||||
| ~~~~~~~~
|
||||
7 | }
|
7
vlib/v/checker/tests/assign_fn_call_on_left_side_err.vv
Normal file
7
vlib/v/checker/tests/assign_fn_call_on_left_side_err.vv
Normal file
@ -0,0 +1,7 @@
|
||||
fn foo(s string) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo('s') = 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user