Skip to content

Commit

Permalink
Fix printing of user-defined option type used for optional arguments (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
riaqn authored Oct 16, 2024
1 parent ec4ded4 commit 5c6a171
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions ocaml/testsuite/tests/printing-types/user-option-args.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(* TEST
toplevel;
*)

(** Test that type of optional argument is printed, even if using a non-predef
option type *)

type nonrec 'a maybe = 'a option;;

let create_property ?x () = let _ = (x : int maybe) in ();;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type nonrec 'a maybe = 'a option
val create_property : ?x:int -> unit -> unit = <fun>

6 changes: 4 additions & 2 deletions ocaml/typing/printtyp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,9 @@ let rec tree_of_typexp mode alloc_mode ty =
let arg_mode = Alloc.zap_to_legacy marg in
let t1 =
if is_optional l then
match get_desc (tpoly_get_mono ty1) with
match
get_desc (Ctype.expand_head !printing_env (tpoly_get_mono ty1))
with
| Tconstr(path, [ty], _)
when Path.same path Predef.path_option ->
tree_of_typexp mode arg_mode ty
Expand Down Expand Up @@ -2273,7 +2275,7 @@ let rec tree_of_class_type mode params =
in
let tr =
if is_optional l then
match get_desc ty with
match get_desc (Ctype.expand_head !printing_env ty) with
| Tconstr(path, [ty], _) when Path.same path Predef.path_option ->
tree_of_typexp mode ty
| _ -> Otyp_stuff "<hidden>"
Expand Down

0 comments on commit 5c6a171

Please sign in to comment.