File tree 3 files changed +17
-4
lines changed
3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -98,13 +98,17 @@ and translateSignatureItem ~config ~outputFileRelative ~resolver ~typeEnv
98
98
signatureItem : Translation.t =
99
99
match signatureItem with
100
100
| {Typedtree. sig_desc = Typedtree. Tsig_type (recFlag , typeDeclarations )} ->
101
+ let recursive = recFlag = Recursive in
102
+ if recursive then
103
+ typeDeclarations
104
+ |> TranslateTypeDeclarations. addRecursiveTypesToTypEnv ~type Env;
101
105
{
102
106
importTypes = [] ;
103
107
codeItems = [] ;
104
108
typeDeclarations =
105
109
typeDeclarations
106
110
|> TranslateTypeDeclarations. translateTypeDeclarations ~config
107
- ~output FileRelative ~recursive: (recFlag = Recursive ) ~resolver
111
+ ~output FileRelative ~recursive ~resolver
108
112
~type Env;
109
113
}
110
114
| {Typedtree. sig_desc = Tsig_value valueDescription } ->
Original file line number Diff line number Diff line change @@ -260,14 +260,17 @@ and translateStructureItem ~config ~outputFileRelative ~resolver ~typeEnv
260
260
(structItem : Typedtree.structure_item ) : Translation.t =
261
261
match structItem with
262
262
| {str_desc = Tstr_type (recFlag , typeDeclarations )} ->
263
+ let recursive = recFlag = Recursive in
264
+ if recursive then
265
+ typeDeclarations
266
+ |> TranslateTypeDeclarations. addRecursiveTypesToTypEnv ~type Env;
263
267
{
264
268
importTypes = [] ;
265
269
codeItems = [] ;
266
270
typeDeclarations =
267
271
typeDeclarations
268
272
|> TranslateTypeDeclarations. translateTypeDeclarations ~config
269
- ~output FileRelative ~recursive: (recFlag = Recursive ) ~resolver
270
- ~type Env;
273
+ ~output FileRelative ~recursive ~resolver ~type Env;
271
274
}
272
275
| {str_desc = Tstr_value (_loc , valueBindings )} ->
273
276
valueBindings
Original file line number Diff line number Diff line change @@ -313,13 +313,19 @@ let hasSomeGADTLeaf constructorDeclarations =
313
313
(fun declaration -> declaration.Types. cd_res != None )
314
314
constructorDeclarations
315
315
316
+ let addRecursiveTypesToTypEnv ~typeEnv typeDeclarations =
317
+ typeDeclarations
318
+ |> List. map (fun ({typ_id} : Typedtree.type_declaration ) -> typ_id)
319
+ |> List. iter (fun type_id ->
320
+ typeEnv |> TypeEnv. newType ~name: (type_id |> Ident. name))
321
+
316
322
let translateTypeDeclaration ~config ~outputFileRelative ~recursive ~resolver
317
323
~typeEnv
318
324
({typ_attributes; typ_id; typ_loc; typ_manifest; typ_params; typ_type} :
319
325
Typedtree.type_declaration ) : CodeItem.typeDeclaration list =
320
326
if ! Debug. translation then
321
327
Log_. item " Translate Type Declaration %s\n " (typ_id |> Ident. name);
322
- if recursive then typeEnv |> TypeEnv. newType ~name: (typ_id |> Ident. name);
328
+
323
329
let typeName = Ident. name typ_id in
324
330
let typeVars =
325
331
typ_params
You can’t perform that action at this time.
0 commit comments