Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 459d28f

Browse files
Tweak outcome printer for object type. (#355)
Adds extra tests + fix minor formatting issues.
1 parent a5cfb9a commit 459d28f

File tree

3 files changed

+62
-27
lines changed

3 files changed

+62
-27
lines changed

src/res_outcome_printer.ml

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ let printPolyVarIdent txt =
435435
)
436436
]
437437
);
438-
Doc.softLine;
439438
Doc.trailingComma;
439+
Doc.softLine;
440440
Doc.rbrace;
441441
]
442442
)
@@ -678,29 +678,22 @@ let printPolyVarIdent txt =
678678
let constraints = match outTypeDecl.otype_cstrs with
679679
| [] -> Doc.nil
680680
| _ -> Doc.group (
681-
Doc.concat [
682-
Doc.line;
683-
Doc.indent (
684-
Doc.concat [
685-
Doc.hardLine;
686-
Doc.join ~sep:Doc.line (List.map (fun (typ1, typ2) ->
687-
Doc.group (
688-
Doc.concat [
689-
Doc.text "constraint ";
690-
printOutTypeDoc typ1;
691-
Doc.text " =";
692-
Doc.indent (
693-
Doc.concat [
694-
Doc.line;
695-
printOutTypeDoc typ2;
696-
]
697-
)
698-
]
699-
)
700-
) outTypeDecl.otype_cstrs)
701-
]
702-
)
703-
]
681+
Doc.indent (
682+
Doc.concat [
683+
Doc.hardLine;
684+
Doc.join ~sep:Doc.line (List.map (fun (typ1, typ2) ->
685+
Doc.group (
686+
Doc.concat [
687+
Doc.text "constraint ";
688+
printOutTypeDoc typ1;
689+
Doc.text " =";
690+
Doc.space;
691+
printOutTypeDoc typ2;
692+
]
693+
)
694+
) outTypeDecl.otype_cstrs)
695+
]
696+
)
704697
) in
705698
Doc.group (
706699
Doc.concat [

tests/oprint/oprint.res

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,18 @@ type obj6 = {"a": int}
264264
type obj7 = {. "a": int}
265265
type obj8<'a> = {.. "a": int} as 'a
266266

267+
type objUser = {"name": string, "age": int}
268+
type objUserWithLongFields = {"name": string, "x": int, "age": int, "looooooongFiiiiiiiieeeeeeeldName": string, "anoooooooooooooooootherLongFiiiiiieeeeeeeldName": int}
269+
270+
type objectCoordinate = {"x": float, "y": float}
271+
type threeDimensionalCoordinate = {...objectCoordinate, "z": float}
272+
type differentSpreadedCoordinate = {"z": float, ...objectCoordinate, "alpha": int}
273+
274+
type multiSpreadedCoordinate = {
275+
...threeDimensionalCoordinate,
276+
"a": int,
277+
...differentSpreadedCoordinate,
278+
"b": int
279+
}
280+
281+
type dotdotObjectCoordinate<'a> = {.. "suuuuuuuuuuuperLooooooooooooongFieldNaaaaaaaaaaaame": float, "suuuuuuuuuuuperLooooooooooooongFieldNaaaaaaaaaaaame2222222222222": float} as 'a

tests/oprint/oprint.res.snapshot

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,37 @@ type obj2 = {"a": int}
404404
type obj3 = {"a": int}
405405
type obj4 = {"a": int}
406406
type obj5<'a> = Js.t<'a>
407-
408407
constraint 'a = {..}
409408
type obj6 = {"a": int}
410409
type obj7 = {"a": int}
411410
type obj8<'a> = 'a
412-
413-
constraint 'a = {.."a": int}
411+
constraint 'a = {.."a": int}
412+
type objUser = {"age": int, "name": string}
413+
type objUserWithLongFields = {
414+
"age": int,
415+
"anoooooooooooooooootherLongFiiiiiieeeeeeeldName": int,
416+
"looooooongFiiiiiiiieeeeeeeldName": string,
417+
"name": string,
418+
"x": int,
419+
}
420+
type objectCoordinate = {"x": float, "y": float}
421+
type threeDimensionalCoordinate = {"x": float, "y": float, "z": float}
422+
type differentSpreadedCoordinate = {
423+
"alpha": int,
424+
"x": float,
425+
"y": float,
426+
"z": float,
427+
}
428+
type multiSpreadedCoordinate = {
429+
"a": int,
430+
"alpha": int,
431+
"b": int,
432+
"x": float,
433+
"y": float,
434+
"z": float,
435+
}
436+
type dotdotObjectCoordinate<'a> = 'a
437+
constraint 'a = {..
438+
"suuuuuuuuuuuperLooooooooooooongFieldNaaaaaaaaaaaame": float,
439+
"suuuuuuuuuuuperLooooooooooooongFieldNaaaaaaaaaaaame2222222222222": float,
440+
}

0 commit comments

Comments
 (0)