Skip to content

Commit b60541e

Browse files
authored
Fix 'Unbound module type' errors that occurred when trying to async import modules (#7783)
* Fix 'Unbound module type' error that occurred when awaiting module in async function with return type constraint * Fix 'Unbound module type' error that occurred when awaiting module in switch case * Add CHANGELOG entry * Add type annotation to case instead of using case.Parsetree.pc_rhs syntax
1 parent fc7226b commit b60541e

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- Preserve `@as(...)` decorator on record fields when creating interface. https://github.com/rescript-lang/rescript/pull/7779
2828
- Fix parse error with nested record types and attributes on the field name that has the nested record type. https://github.com/rescript-lang/rescript/pull/7781
2929
- Fix ppx resolution with package inside monorepo. https://github.com/rescript-lang/rescript/pull/7776
30+
- Fix 'Unbound module type' errors that occurred when trying to async import modules. https://github.com/rescript-lang/rescript/pull/7783
3031

3132
#### :memo: Documentation
3233

compiler/frontend/bs_builtin_ppx.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,14 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t)
568568
aux then_expr @ aux else_expr
569569
| Pexp_construct (_, Some expr) -> aux expr
570570
| Pexp_fun {rhs = expr} | Pexp_newtype (_, expr) -> aux expr
571+
| Pexp_constraint (expr, _) -> aux expr
572+
| Pexp_match (expr, cases) ->
573+
let case_results =
574+
List.fold_left
575+
(fun acc (case : Parsetree.case) -> aux case.pc_rhs @ acc)
576+
[] cases
577+
in
578+
aux expr @ case_results
571579
| _ -> acc
572580
in
573581
aux pvb_expr @ spelunk_vbs acc tl

tests/tests/src/Import.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ async function f7() {
120120
return 1;
121121
}
122122

123+
async function f8() {
124+
await import("rescript/lib/es6/Belt_MutableQueue.js");
125+
return 1;
126+
}
127+
128+
async function f9(value) {
129+
if (value !== undefined) {
130+
await import("rescript/lib/es6/Belt_HashMapInt.js");
131+
return;
132+
}
133+
134+
}
135+
123136
let each = M1.forEach;
124137

125138
let M2;
@@ -145,5 +158,7 @@ export {
145158
f5,
146159
f6,
147160
f7,
161+
f8,
162+
f9,
148163
}
149164
/* Not a pure module */

tests/tests/src/Import.res

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,17 @@ let f7 = async () => {
9090
0
9191
}
9292
}
93+
94+
let f8 = async (): int => {
95+
module MQ = await Belt.MutableQueue
96+
1
97+
}
98+
99+
let f9 = async value => {
100+
switch value {
101+
| Some(_) =>
102+
module HashMapInt = await Belt.HashMap.Int
103+
()
104+
| None => ()
105+
}
106+
}

0 commit comments

Comments
 (0)