Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- Fix OxCaml with-bounds for arbitrary types (@art-w, #1466)

### Fixed
- Fix optional arguments rendering as `?arg:???` in modules without an mli on
OCaml 5.5 (@jonludlam, #1489)
- Remove requirement for ppx_expect in tests (@jonludlam, #1445)
- Fix resolving functor through `module type of` (@Leonidas-from-XIV, #1471)
- Fix odoc_driver's detection of `stdlib` when it is in `$prefix/lib64`, requires ocamlfind >= 1.9.8 (@katrinafyi, #1477, #1474)
Expand Down
9 changes: 7 additions & 2 deletions src/loader/cmi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ let opt_iter f = function
| None -> ()
| Some x -> f x

(* From OCaml 5.5, the argument types of inferred arrows are wrapped in a
trivial [Tpoly] node. Look through it when unwrapping optional arguments. *)
let strip_trivial_poly typ =
match Compat.get_desc typ with Tpoly (typ, []) -> typ | _ -> typ

let read_label lbl =
let open TypeExpr in
#if defined OXCAML
Expand Down Expand Up @@ -799,7 +804,7 @@ and read_type_expr_modal env implied_modes typ =
let lbl,arg =
match lbl with
| Some (Optional s) -> (
match Compat.get_desc arg with
match Compat.get_desc (strip_trivial_poly arg) with
| Tconstr(_option, [arg], _) ->
lbl, read_type_expr env arg (* Unwrap option if possible *)
| _ ->
Expand Down Expand Up @@ -1384,7 +1389,7 @@ let rec read_class_type env parent params =
let lbl, arg =
match lbl with
| Some (Optional s) -> (
match Compat.get_desc arg with
match Compat.get_desc (strip_trivial_poly arg) with
| Tconstr(_option, [arg], _) ->
lbl, read_type_expr env arg (* Unwrap option if possible *)
| _ ->
Expand Down
2 changes: 1 addition & 1 deletion test/xref2/dune
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
; 5.5.0 and above

(cram
(applies_to github_issue_1426)
(applies_to github_issue_1426 optional_arg_inferred)
(enabled_if
(>= %{ocaml_version} 5.5.0)))

Expand Down
20 changes: 20 additions & 0 deletions test/xref2/optional_arg_inferred.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Optional arguments of values whose signature is inferred from the
implementation (a module with no mli). From OCaml 5.5 the compiler wraps the
argument types of inferred arrows in a trivial [Tpoly] node, which must not
stop odoc from recognising the [option] beneath it.

$ cat test.ml
let f ?force x = ignore force; x
let exit = f

$ ocamlc -c -bin-annot test.ml
$ odoc compile test.cmt
$ odoc link test.odoc

The labels should be [Optional]; [RawOptional] renders as [?force:???]:

$ odoc_print test.odocl | jq -c '.. | .["Arrow"]? | select(.) | .[0]'
{"Some":{"Optional":"force"}}
"None"
{"Some":{"Optional":"force"}}
"None"
2 changes: 2 additions & 0 deletions test/xref2/optional_arg_inferred.t/test.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let f ?force x = ignore force; x
let exit = f
Loading