Skip to content

Commit

Permalink
Fix lint about list length comparisons
Browse files Browse the repository at this point in the history
Now it also reports about `List.length xs < 0` and `0 > List.length xs`.

Signed-off-by: s-khechnev <hechnev@gmail.com>
  • Loading branch information
s-khechnev authored and Kakadu committed May 24, 2023
1 parent 24dcb7b commit 5e56a9c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/typed/List_length.ml
Expand Up @@ -78,7 +78,7 @@ let pat
Tast_pattern.t
=
let open Tast_pattern in
let ops = [ ">=", "<=", 0; "<=", ">=", 0; ">", "<", 0; "=", "=", 0 ] in
let ops = [ ">=", "<=", 0; "<=", ">=", 0; ">", "<", 0; "<", ">", 0; "=", "=", 0 ] in
let single (op, dualop, n) =
let open Tast_pattern in
(* TODO: understand difference between Stdlib and Stdlib! *)
Expand Down
2 changes: 2 additions & 0 deletions tests/typed/list_len.t/list_len.ml
Expand Up @@ -11,3 +11,5 @@ let __ xs = List.length xs > 0
let __ xs = 0 < List.length xs

let __ xs = 0 = List.length xs

let __ xs = 0 > List.length xs
10 changes: 10 additions & 0 deletions tests/typed/list_len.t/run.t
@@ -1,5 +1,10 @@
$ dune build
$ zanuda -no-check-filesystem -no-top_file_license -dir . -ordjsonl /dev/null
File "list_len.ml", line 1, characters 12-30:
1 | let __ xs = List.length xs < 0
^^^^^^^^^^^^^^^^^^
Alert zanuda-linter: Bad measurement of a list (with non-negative size)
Between 'List.length xs' and '0'.
File "list_len.ml", line 3, characters 12-31:
3 | let __ xs = List.length xs <= 0
^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -30,3 +35,8 @@
^^^^^^^^^^^^^^^^^^
Alert zanuda-linter: Bad measurement of a list (with non-negative size)
Between '0' and 'List.length xs'.
File "list_len.ml", line 15, characters 12-30:
15 | let __ xs = 0 > List.length xs
^^^^^^^^^^^^^^^^^^
Alert zanuda-linter: Bad measurement of a list (with non-negative size)
Between '0' and 'List.length xs'.

0 comments on commit 5e56a9c

Please sign in to comment.