parent
f59119485a
commit
11784279ba
|
@ -2465,6 +2465,10 @@ fn (mut c Checker) array_builtin_method_call(mut call_expr ast.CallExpr, left_ty
|
|||
// position of `it` doesn't matter
|
||||
scope_register_it(mut call_expr.scope, call_expr.pos, elem_typ)
|
||||
} else if method_name == 'sort' {
|
||||
if call_expr.left is ast.CallExpr {
|
||||
c.error('the `sort()` method can be called only on mutable receivers, but `$call_expr.left` is a call expression',
|
||||
call_expr.pos)
|
||||
}
|
||||
c.fail_if_immutable(call_expr.left)
|
||||
// position of `a` and `b` doesn't matter, they're the same
|
||||
scope_register_a_b(mut call_expr.scope, call_expr.pos, elem_typ)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
vlib/v/checker/tests/fn_return_array_sort_err.vv:6:14: error: the `sort()` method can be called only on mutable receivers, but `ret_array()` is a call expression
|
||||
4 |
|
||||
5 | fn main() {
|
||||
6 | ret_array().sort()
|
||||
| ~~~~~~
|
||||
7 | }
|
|
@ -0,0 +1,7 @@
|
|||
fn ret_array() []int {
|
||||
return [1, 3, 2]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
ret_array().sort()
|
||||
}
|
Loading…
Reference in New Issue