checker: add a checker error for fn calls on left side of an assignment (#5993)
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 {
|
||||
|
|
|
@ -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 | }
|
|
@ -0,0 +1,7 @@
|
|||
fn foo(s string) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo('s') = 1
|
||||
}
|
Loading…
Reference in New Issue