checker: check arguments count of sort (#9105)
parent
746fe47e94
commit
4f02da00ba
|
@ -1323,6 +1323,10 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
|
||||||
c.fail_if_immutable(call_expr.left)
|
c.fail_if_immutable(call_expr.left)
|
||||||
// position of `a` and `b` doesn't matter, they're the same
|
// position of `a` and `b` doesn't matter, they're the same
|
||||||
scope_register_ab(mut call_expr.scope, call_expr.pos, array_info.elem_type)
|
scope_register_ab(mut call_expr.scope, call_expr.pos, array_info.elem_type)
|
||||||
|
|
||||||
|
if call_expr.args.len > 1 {
|
||||||
|
c.error('expected 0 or 1 argument, but got $call_expr.args.len', call_expr.pos)
|
||||||
|
}
|
||||||
// Verify `.sort(a < b)`
|
// Verify `.sort(a < b)`
|
||||||
if call_expr.args.len > 0 {
|
if call_expr.args.len > 0 {
|
||||||
if call_expr.args[0].expr !is ast.InfixExpr {
|
if call_expr.args[0].expr !is ast.InfixExpr {
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/checker/tests/array_sort_err.vv:3:6: error: expected 0 or 1 argument, but got 2
|
||||||
|
1 | fn main() {
|
||||||
|
2 | mut arr := [3, 2, 1]
|
||||||
|
3 | arr.sort(a < b, a)
|
||||||
|
| ~~~~~~~~~~~~~~
|
||||||
|
4 | }
|
|
@ -0,0 +1,4 @@
|
||||||
|
fn main() {
|
||||||
|
mut arr := [3, 2, 1]
|
||||||
|
arr.sort(a < b, a)
|
||||||
|
}
|
Loading…
Reference in New Issue