Skip to content

Fix issue with recursive modules and uncurried. #6575

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

Merged
merged 1 commit into from
Jan 17, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

# 11.0.1 (Unreleased)

#### :bug: Bug Fix
- Fix issue with recursive modules and uncurried. https://github.com/rescript-lang/rescript-compiler/pull/6575

# 11.0.0

No changes compared to rc.9.
Expand Down
24 changes: 14 additions & 10 deletions jscomp/ml/transl_recmodule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,22 @@ let init_shape modl =
match sg with
| [] -> []
| Sig_value (id, { val_kind = Val_reg; val_type = ty }) :: rem ->
let is_function t =
Ast_uncurried_utils.typeIsUncurriedFun t || match t.desc with
| Tarrow _ -> true
| _ -> false in
let init_v =
match Ctype.expand_head env ty with
| { desc = Tarrow (_, _, _, _) } ->
Const_pointer
( 0,
Pt_constructor
{
name = "Function";
const = cstr_const;
non_const = cstr_non_const;
attrs = [];
} )
| t when is_function t ->
Const_pointer
( 0,
Pt_constructor
{
name = "Function";
const = cstr_const;
non_const = cstr_non_const;
attrs = [];
} )
| { desc = Tconstr (p, _, _) } when Path.same p Predef.path_lazy_t ->
Const_pointer
( 1,
Expand Down
3 changes: 2 additions & 1 deletion jscomp/test/build.ninja

Large diffs are not rendered by default.

207 changes: 207 additions & 0 deletions jscomp/test/recmodule.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions jscomp/test/recmodule.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
type params = {id: string}
type req = {params: params}

module Entity = {
type light = {
id: string,
name: string,
}
}

module UseCase = {
module type Layer = {
let getLight: string => promise<unit>
}

module type Deps = {
let presentLight: Entity.light => promise<unit>
}

module MakeLayer = (Deps: Deps): Layer => {
let getLight = id => {
Deps.presentLight({
id,
name: "Light 1",
})
}
}
}

module Adapter = {
module type Layer = {
let handleGetLight: req => promise<unit>
let presentLight: Entity.light => promise<unit>
}

module type Deps = {
let presentJson: ('a, ~status: int) => promise<unit>
}

module MakeLayer = (Deps: Deps, UC: UseCase.Layer): Layer => {
let presentLight = light => light->Deps.presentJson(~status=200)

let handleGetLight = req => {
UC.getLight(req.params.id)
}
}
}

module Infra = {
module type Layer = {
let presentJson: ('a, ~status: int) => promise<unit>
let routes: unit => array<(string, req => promise<unit>)>
}

module type Deps = {
let handleGetLight: req => promise<unit>
}

module MakeLayer = (Deps: Deps): Layer => {
let presentJson = (json, ~status) => assert false

let routes = () => [("/lights", Deps.handleGetLight)]
}
}

module App = {
module rec I: Infra.Layer = Infra.MakeLayer(A)
and A: Adapter.Layer = Adapter.MakeLayer(I, U)
and U: UseCase.Layer = UseCase.MakeLayer(A)
}