diff --git a/analysis/src/vendor/res_outcome_printer/res_outcome_printer.ml b/analysis/src/vendor/res_outcome_printer/res_outcome_printer.ml index 2c1f53490..1c5a4eeac 100644 --- a/analysis/src/vendor/res_outcome_printer/res_outcome_printer.ml +++ b/analysis/src/vendor/res_outcome_printer/res_outcome_printer.ml @@ -348,7 +348,7 @@ let printPolyVarIdent txt = | [], [] -> Doc.nil | labels, types -> let i = ref 0 in - let package = Doc.join ~sep:Doc.line (List.map2 (fun lbl typ -> + let package = Doc.join ~sep:Doc.line ((List.map2 [@doesNotRaise]) (fun lbl typ -> Doc.concat [ Doc.text (if i.contents > 0 then "and " else "with "); Doc.text lbl; @@ -376,13 +376,21 @@ let printPolyVarIdent txt = let (typArgs, typ) = collectArrowArgs typ [] in let args = Doc.join ~sep:(Doc.concat [Doc.comma; Doc.line]) ( List.map (fun (lbl, typ) -> - if lbl = "" then + let lblLen = String.length lbl in + if lblLen = 0 then printOutTypeDoc typ else + let (lbl, optionalIndicator) = + (* the ocaml compiler hardcodes the optional label inside the string of the label in printtyp.ml *) + match String.unsafe_get lbl 0 with + | '?' -> ((String.sub [@doesNotRaise]) lbl 1 (lblLen - 1) , Doc.text "=?") + | _ -> (lbl, Doc.nil) + in Doc.group ( Doc.concat [ Doc.text ("~" ^ lbl ^ ": "); - printOutTypeDoc typ + printOutTypeDoc typ; + optionalIndicator ] ) ) typArgs @@ -468,7 +476,7 @@ let printPolyVarIdent txt = and printObjectFields fields rest = let dots = match rest with | Some non_gen -> Doc.text ((if non_gen then "_" else "") ^ "..") - | None -> Doc.nil + | None -> if fields = [] then Doc.dot else Doc.nil in Doc.group ( Doc.concat [ diff --git a/analysis/tests/src/expected/Div.res.txt b/analysis/tests/src/expected/Div.res.txt index 095c7d795..0c0057dba 100644 --- a/analysis/tests/src/expected/Div.res.txt +++ b/analysis/tests/src/expected/Div.res.txt @@ -1,5 +1,5 @@ Hover tests/src/Div.res 1:10 -{"contents": "```rescript\n(\n string,\n ~?props: ReactDOMRe.domProps,\n array,\n) => React.element\n```"} +{"contents": "```rescript\n(\n string,\n ~props: ReactDOMRe.domProps=?,\n array,\n) => React.element\n```"} Complete tests/src/Div.res 3:3 [{ diff --git a/analysis/tests/src/expected/Jsx.resi.txt b/analysis/tests/src/expected/Jsx.resi.txt index deac2dbe9..f82257ca3 100644 --- a/analysis/tests/src/expected/Jsx.resi.txt +++ b/analysis/tests/src/expected/Jsx.resi.txt @@ -1,5 +1,5 @@ Hover tests/src/Jsx.resi 1:4 -{"contents": "```rescript\n(~first: string, ~?key: string, unit) => {\"first\": string}\n```"} +{"contents": "```rescript\n(~first: string, ~key: string=?, unit) => {\"first\": string}\n```"} Hover tests/src/Jsx.resi 4:4 {"contents": "```rescript\nint\n```"}