Skip to content

Commit

Permalink
Fix Array.of_seq (#1897)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thierry-martinez authored and xavierleroy committed Jul 11, 2018
1 parent 2f3710e commit b5ff016
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions 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)
---------------------------

Expand Down
2 changes: 1 addition & 1 deletion stdlib/array.ml
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions testsuite/tests/lib-seq/test.ml
Expand Up @@ -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";;


0 comments on commit b5ff016

Please sign in to comment.