Skip to content

Commit

Permalink
fix(compiler): Ensure reprovided types unify (#2051)
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer committed Mar 2, 2024
1 parent 029059f commit 4c3203c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compiler/src/typed/typemod.re
Expand Up @@ -674,6 +674,15 @@ let rec type_module = (~toplevel=false, anchor, env, statements) => {
| Some(_) => failwith("Impossible: invalid alias")
| None => Ident.create(name.txt)
};
let type_ =
switch (type_path) {
| PExternal(_) => {
...type_,
type_manifest:
Some(Ctype.newconstr(type_path, type_.type_params)),
}
| PIdent(_) => type_
};
([TSigType(id, type_, TRecNot), ...sigs], stmts);
| PProvideException({name: {txt: IdentName(name)}, alias, loc}) =>
let ext = Typetexp.find_exception(env, loc, IdentName(name));
Expand Down
5 changes: 5 additions & 0 deletions compiler/test/input/reprovideTypeUnifyA.gr
@@ -0,0 +1,5 @@
module ReprovideTypeUnifyA

from "./reprovideTypeUnifyB" include ReprovideTypeUnifyB
use ReprovideTypeUnifyB.{ type T, a }
print(a == { x: 1, })
6 changes: 6 additions & 0 deletions compiler/test/input/reprovideTypeUnifyB.gr
@@ -0,0 +1,6 @@
module ReprovideTypeUnifyB

from "./reprovideTypeUnifyC" include ReprovideTypeUnifyC
use ReprovideTypeUnifyC.{ type T }
let a = { x: 1, }
provide { type T, a }
5 changes: 5 additions & 0 deletions compiler/test/input/reprovideTypeUnifyC.gr
@@ -0,0 +1,5 @@
module ReprovideTypeUnifyC

provide record T {
x: Number,
}
6 changes: 6 additions & 0 deletions compiler/test/suites/provides.re
Expand Up @@ -13,6 +13,7 @@ describe("provides", ({test, testSkip}) => {
);
let assertCompileError = makeCompileErrorRunner(test);
let assertRun = makeRunner(test_or_skip);
let assertFileRun = makeFileRunner(test_or_skip);
let assertRunError = makeErrorRunner(test_or_skip);
let assertHasWasmExport = (name, prog, expectedExports) => {
test(
Expand Down Expand Up @@ -249,4 +250,9 @@ describe("provides", ({test, testSkip}) => {
"module Test; enum T { A }; provide let a = A; provide { type T }",
[("GRAIN$EXPORT$a", Binaryen.Export.external_global)],
);
assertFileRun(
"issue_1886_type_reprovided_unify",
"reprovideTypeUnifyA",
"true\n",
);
});

0 comments on commit 4c3203c

Please sign in to comment.