From 1e7c6e044104afb0bf42a54a718d1d50598c1cc0 Mon Sep 17 00:00:00 2001 From: Kakadu Date: Sun, 28 Jul 2024 12:37:04 +0300 Subject: [PATCH] Improve tests for lint 'mutability_check' Signed-off-by: Kakadu --- tests/typed/hashtables.t/.zanuda | 1 + tests/typed/hashtables.t/Counter.ml | 3 +++ tests/typed/hashtables.t/dune | 2 +- tests/typed/hashtables.t/run.t | 8 ++++++++ tests/typed/hashtables.t/tast.ml | 3 +++ 5 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/typed/hashtables.t/.zanuda create mode 100644 tests/typed/hashtables.t/Counter.ml create mode 100644 tests/typed/hashtables.t/tast.ml diff --git a/tests/typed/hashtables.t/.zanuda b/tests/typed/hashtables.t/.zanuda new file mode 100644 index 0000000..f8d7a98 --- /dev/null +++ b/tests/typed/hashtables.t/.zanuda @@ -0,0 +1 @@ +forward mutability_check ignore tast.ml,tast.ml,tast.ml,tast.ml \ No newline at end of file diff --git a/tests/typed/hashtables.t/Counter.ml b/tests/typed/hashtables.t/Counter.ml new file mode 100644 index 0000000..733faa0 --- /dev/null +++ b/tests/typed/hashtables.t/Counter.ml @@ -0,0 +1,3 @@ +let count = + let last = ref 0 in + (fun () -> incr last; !last) \ No newline at end of file diff --git a/tests/typed/hashtables.t/dune b/tests/typed/hashtables.t/dune index af3a1a5..3cc24f5 100644 --- a/tests/typed/hashtables.t/dune +++ b/tests/typed/hashtables.t/dune @@ -2,4 +2,4 @@ (name test_hashtables) (wrapped false) (libraries base) - (modules Hashtables)) + (modules Hashtables Counter Tast)) diff --git a/tests/typed/hashtables.t/run.t b/tests/typed/hashtables.t/run.t index 5943cbe..9342afc 100644 --- a/tests/typed/hashtables.t/run.t +++ b/tests/typed/hashtables.t/run.t @@ -32,3 +32,11 @@ 24 | type args = { mutable count: int } ^^^^^^^^^^^^^^^^^^ Alert zanuda-linter: Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable `ref`erences and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there. + File "Counter.ml", line 3, characters 18-22: + 3 | (fun () -> incr last; !last) + ^^^^ + Alert zanuda-linter: Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable `ref`erences and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there. + File "Counter.ml", line 3, characters 25-29: + 3 | (fun () -> incr last; !last) + ^^^^ + Alert zanuda-linter: Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable `ref`erences and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there. diff --git a/tests/typed/hashtables.t/tast.ml b/tests/typed/hashtables.t/tast.ml new file mode 100644 index 0000000..5c32fdb --- /dev/null +++ b/tests/typed/hashtables.t/tast.ml @@ -0,0 +1,3 @@ +(** Report about this line will not appear because of .zanuda file *) +let last = ref 0 +let() = incr last \ No newline at end of file