Skip to content

Bug: Custom Indexing Operators are sometimes re-ordered #972

@mseri

Description

@mseri

Describe the bug
ocamlformat moves around the extended indexing operators (https://caml.inria.fr/pub/docs/manual-ocaml/manual042.html) if the module containing them is not open in a bigger scope. I attach here the diff from a recent owl example, and below a small repro:

-        sol_planets.Mat.${[ []; [ 3*i ] ]}
-        sol_planets.Mat.${[ []; [ 3*i + 1 ] ]};
-
+        (Mat.( .${} ) sol_planets [ []; [ 3 * i ] ])
+        (Mat.( .${} ) sol_planets [ []; [ (3 * i) + 1 ] ]);

How to Reproduce
Steps to reproduce the behavior:

  • What is the formatted file? Please try to minimize the code snippet.

The following code

open Owl

let () =
  let m = Mat.zeros 5 5 in
  m.Mat.${[[2];[5]]} |> ignore;
  let open Mat in
  m.${[[2];[5]]} |> ignore;

produces the following diff:

@@ -2,6 +2,6 @@ open Owl
 
 let () =
   let m = Mat.zeros 5 5 in
-  m.Mat.${[[2];[5]]} |> ignore;
+  Mat.( .${} ) m [ [ 2 ]; [ 5 ] ] |> ignore;
   let open Mat in
-  m.${[[2];[5]]} |> ignore;
+  m.${[ [ 2 ]; [ 5 ] ]} |> ignore
  • What are the selected options?

My .ocamlformat file is:

profile=janestreet
wrap-comments=false
let-binding-spacing=sparse

The option --print-config prints the configuration on the standard output, please put the result of this command in the report if you are not sure which option causes the issue.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions