checker: error if assigning to a function (#6581)
parent
7d65e4cb10
commit
92630a2821
|
@ -1944,6 +1944,8 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
|
|||
if assign_stmt.op !in [.assign, .decl_assign] {
|
||||
c.error('cannot modify blank `_` identifier', left.pos)
|
||||
}
|
||||
} else if left.info !is ast.IdentVar {
|
||||
c.error('cannot assign to $left.kind `$left.name`', left.pos)
|
||||
} else {
|
||||
if is_decl {
|
||||
c.check_valid_snake_case(left.name, 'variable name', left.pos)
|
||||
|
|
|
@ -5,3 +5,17 @@ vlib/v/checker/tests/assign_multi_immutable_err.vv:4:2: error: `a` is immutable,
|
|||
| ^
|
||||
5 |
|
||||
6 | println('$a, $b')
|
||||
vlib/v/checker/tests/assign_multi_immutable_err.vv:18:5: error: cannot assign to function `error`
|
||||
16 |
|
||||
17 | fn assign_fn() {
|
||||
18 | _, error = g()
|
||||
| ~~~~~
|
||||
19 | g = f()
|
||||
20 | }
|
||||
vlib/v/checker/tests/assign_multi_immutable_err.vv:19:2: error: cannot assign to function `g`
|
||||
17 | fn assign_fn() {
|
||||
18 | _, error = g()
|
||||
19 | g = f()
|
||||
| ^
|
||||
20 | }
|
||||
21 |
|
||||
|
|
|
@ -5,3 +5,17 @@ fn main() {
|
|||
|
||||
println('$a, $b')
|
||||
}
|
||||
|
||||
fn f() int {
|
||||
return 2
|
||||
}
|
||||
|
||||
fn g() (int, int) {
|
||||
return 1, 2
|
||||
}
|
||||
|
||||
fn assign_fn() {
|
||||
_, error = g()
|
||||
g = f()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue