summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthierry-martinez <thierry.martinez@inria.fr>2018-07-11 19:08:04 +0200
committerXavier Leroy <xavier.leroy@inria.fr>2018-07-11 19:15:36 +0200
commitb5ff0163728a65525ebcca88043049aa168bbb58 (patch)
tree7b2b18d3748c5e9796073941ef89eeb4add540a0
parent2f3710e610d6005a5cb94c92021f3069136ee895 (diff)
downloadocaml-b5ff0163728a65525ebcca88043049aa168bbb58.tar.gz
Fix Array.of_seq (#1897)
Reported at https://caml.inria.fr/mantis/view.php?id=7820 Array.of_seq applies a circular permutation of one cell to the right on the sequence. With OCaml 4.07.0 and trunk, we have - : int array = [|3; 1; 2|] In stdlib/array.ml, line 337 (last line of of_rev_list), we have fill (len-1) tl whereas it should be fill (len-2) tl since hd, which should be assigned to the cell (len - 1), is skipped.
-rw-r--r--Changes8
-rw-r--r--stdlib/array.ml2
-rw-r--r--testsuite/tests/lib-seq/test.ml9
3 files changed, 18 insertions, 1 deletions
diff --git a/Changes b/Changes
index 25976617b3..62d549c017 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,11 @@
+OCaml 4.07 maintenance branch
+-----------------------------
+
+- MPR#7820, GPR#1897: Fix Array.of_seq. This function used to apply a circular
+ permutation of one cell to the right on the sequence.
+ (Thierry Martinez, review by Nicolás Ojeda Bär)
+
+
OCaml 4.07.0 (10 July 2018)
---------------------------
diff --git a/stdlib/array.ml b/stdlib/array.ml
index d29a04faab..a693f4a72f 100644
--- a/stdlib/array.ml
+++ b/stdlib/array.ml
@@ -334,7 +334,7 @@ let of_rev_list = function
[] -> a
| hd::tl -> unsafe_set a i hd; fill (i-1) tl
in
- fill (len-1) tl
+ fill (len-2) tl
let of_seq i =
let l = Seq.fold_left (fun acc x -> x::acc) [] i in
diff --git a/testsuite/tests/lib-seq/test.ml b/testsuite/tests/lib-seq/test.ml
index 934a001efb..ca38d4663c 100644
--- a/testsuite/tests/lib-seq/test.ml
+++ b/testsuite/tests/lib-seq/test.ml
@@ -13,6 +13,15 @@ let () =
()
;;
+(* MPR 7820 *)
+let () =
+ assert
+ ([| 1;2;3 |] =
+ (Array.to_seq [| 1;2;3 |]
+ |> Array.of_seq));
+ ()
+;;
+
let () = print_endline "OK";;