Skip to content

Commit 22f68af

Browse files
authored
Fix generation of interfaces for module types containing multiple type constraints (#7825)
* Failing test for generating interface where a module has multiple type constraints * Fix printing of module types with multiple type constraints * Add CHANGELOG
1 parent 5eaab84 commit 22f68af

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#### :bug: Bug fix
2222

23+
- Fix generation of interfaces for module types containing multiple type constraints. https://github.com/rescript-lang/rescript/pull/7825
24+
2325
#### :memo: Documentation
2426

2527
#### :nail_care: Polish

compiler/syntax/src/res_outcome_printer.ml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,18 @@ let rec print_out_type_doc (out_type : Outcometree.out_type) =
217217
Doc.join ~sep:Doc.line
218218
((List.map2 [@doesNotRaise])
219219
(fun lbl typ ->
220-
Doc.concat
221-
[
222-
Doc.text
223-
(if i.contents > 0 then "and type " else "with type ");
224-
Doc.text lbl;
225-
Doc.text " = ";
226-
print_out_type_doc typ;
227-
])
220+
let result =
221+
Doc.concat
222+
[
223+
Doc.text
224+
(if i.contents > 0 then "and type " else "with type ");
225+
Doc.text lbl;
226+
Doc.text " = ";
227+
print_out_type_doc typ;
228+
]
229+
in
230+
incr i;
231+
result)
228232
labels types)
229233
in
230234
Doc.indent (Doc.concat [Doc.line; package])

tests/analysis_tests/tests/src/CreateInterface.res

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,24 @@ module ComponentWithPolyProp = {
171171
<div className />
172172
}
173173
}
174+
175+
module OrderedSet = {
176+
type t<'a, 'identity> = {
177+
cmp: ('a, 'a) => int,
178+
set: Belt.Set.t<'a, 'identity>,
179+
array: array<'a>,
180+
}
181+
182+
let make = (
183+
type value identity,
184+
~id: module(Belt.Id.Comparable with type t = value and type identity = identity),
185+
): t<value, identity> => {
186+
let module(M) = id
187+
188+
{
189+
cmp: M.cmp->Belt.Id.getCmpInternal,
190+
set: Belt.Set.make(~id),
191+
array: [],
192+
}
193+
}
194+
}

tests/analysis_tests/tests/src/expected/CreateInterface.res.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,12 @@ module ComponentWithPolyProp: {
124124
@react.component
125125
let make: (~size: [< #large | #small]=?) => Jsx.element
126126
}
127+
module OrderedSet: {
128+
type t<'a, 'identity> = {
129+
cmp: ('a, 'a) => int,
130+
set: Belt.Set.t<'a, 'identity>,
131+
array: array<'a>,
132+
}
133+
let make: (~id: module(Belt.Id.Comparable with type identity = 'a and type t = 'b)) => t<'b, 'a>
134+
}
127135

0 commit comments

Comments
 (0)