Skip to content

Commit 1c43bd6

Browse files
authored
fix(compiler): Allow providing values of types provided later (#1897)
1 parent 79ab814 commit 1c43bd6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

compiler/src/typed/typed_well_formedness.re

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ let ensure_no_escaped_types = (signature, statements) => {
9191
Ident.Set.empty,
9292
statements,
9393
);
94+
// Remove types provided after initial type definition (with `provide { type X }` statement)
95+
let private_idents =
96+
List.fold_left(
97+
(private_idents, sig_) => {
98+
switch (sig_) {
99+
| Types.TSigType(id, _, _) =>
100+
switch (Ident.Set.find_first_opt(Ident.equal(id), private_idents)) {
101+
| Some(to_remove) => Ident.Set.remove(to_remove, private_idents)
102+
| None => private_idents
103+
}
104+
| _ => private_idents
105+
}
106+
},
107+
private_idents,
108+
signature,
109+
);
94110
let ctx_loc = ctx => {
95111
switch (ctx) {
96112
| Value(loc)

compiler/test/suites/provides.re

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,24 @@ describe("provides", ({test, testSkip}) => {
189189
("GRAIN$EXPORT$y", Binaryen.Export.external_global),
190190
],
191191
);
192+
assertHasWasmExport(
193+
"issue_1884_type_provided_later1",
194+
"module Test; enum T { A }; let a = A; provide { type T }; provide { a }",
195+
[("GRAIN$EXPORT$a", Binaryen.Export.external_global)],
196+
);
197+
assertHasWasmExport(
198+
"issue_1884_type_provided_later2",
199+
"module Test; enum T { A }; let a = A; provide { a, type T }",
200+
[("GRAIN$EXPORT$a", Binaryen.Export.external_global)],
201+
);
202+
assertHasWasmExport(
203+
"issue_1884_type_provided_later3",
204+
"module Test; enum T { A }; let a = A; provide { a }; provide { type T }",
205+
[("GRAIN$EXPORT$a", Binaryen.Export.external_global)],
206+
);
207+
assertHasWasmExport(
208+
"issue_1884_type_provided_later4",
209+
"module Test; enum T { A }; provide let a = A; provide { type T }",
210+
[("GRAIN$EXPORT$a", Binaryen.Export.external_global)],
211+
);
192212
});

0 commit comments

Comments
 (0)