Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): Re-providing types #1874

Merged
merged 1 commit into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions compiler/src/typed/typemod.re
Original file line number Diff line number Diff line change
Expand Up @@ -652,19 +652,19 @@ let rec type_module = (~toplevel=false, anchor, env, statements) => {
],
);
| PProvideType({name: {txt: IdentName(name)}, alias, loc}) =>
let (type_id, _) = Typetexp.find_type(env, loc, IdentName(name));
switch (alias) {
| Some({txt: IdentName(alias)}) =>
type_export_aliases :=
[
(type_id, PIdent(Ident.create(alias.txt))),
...type_export_aliases^,
]
| Some(_) => failwith("Impossible: invalid alias")
| None => ()
};
let type_ = Env.find_type(type_id, env);
([TSigType(Path.head(type_id), type_, TRecNot), ...sigs], stmts);
let (type_path, type_) =
Typetexp.find_type(env, loc, IdentName(name));
let id =
switch (alias) {
| Some({txt: IdentName(alias)}) =>
let id = Ident.create(alias.txt);
type_export_aliases :=
[(type_path, PIdent(id)), ...type_export_aliases^];
id;
| Some(_) => failwith("Impossible: invalid alias")
| None => Ident.create(Path.last(type_path))
};
([TSigType(id, type_, TRecNot), ...sigs], stmts);
| PProvideModule({name: {txt: IdentName(name)}, alias, loc}) =>
let (mod_path, mod_decl) =
Typetexp.find_module(env, loc, IdentName(name));
Expand Down Expand Up @@ -934,7 +934,11 @@ let rec type_module = (~toplevel=false, anchor, env, statements) => {
switch (get_alias(type_export_aliases^, PIdent(id))) {
| None => TSigType(id, resolve_type_decl(decl), rs)
| Some((name, alias)) =>
TSigType(Path.head(alias), resolve_type_decl(decl), rs)
TSigType(
Ident.create(Path.last(alias)),
resolve_type_decl(decl),
rs,
)
}
| TSigValue(id, {val_type, val_kind} as vd) =>
let val_kind =
Expand Down
5 changes: 5 additions & 0 deletions compiler/test/suites/includes.re
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,9 @@ describe("includes", ({test, testSkip}) => {
"brokenIncludes/main",
"./broken.gr\", line 4, characters 8-15",
);
assertRun(
"reprovide_type",
"include \"reprovideType\"; from ReprovideType use { type Type }; print(A)",
"A\n",
);
});
7 changes: 7 additions & 0 deletions compiler/test/test-libs/provideType.gr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ProvideType

provide enum Type {
A,
B,
C,
}
7 changes: 7 additions & 0 deletions compiler/test/test-libs/reprovideType.gr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ReprovideType

include "./provideType"

from ProvideType use { type Type }

provide { type Type }