diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f90555c57..18564c2ed8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ # 12.0.0-alpha.15 (Unreleased) +#### :bug: Bug fix +- ignore inferred arity in functions inside `%raw` functions, leaving to `%ffi` the responsibility to check the arity since it gives an error in case of mismatch. https://github.com/rescript-lang/rescript/pull/7542 + #### :nail_care: Polish - Better error message for when trying to await something that is not a promise. https://github.com/rescript-lang/rescript/pull/7561 diff --git a/compiler/core/lam_arity_analysis.ml b/compiler/core/lam_arity_analysis.ml index 6e0027ca5f..ee3d91f154 100644 --- a/compiler/core/lam_arity_analysis.ml +++ b/compiler/core/lam_arity_analysis.ml @@ -69,8 +69,6 @@ let rec get_arity (meta : Lam_stats.t) (lam : Lam.t) : Lam_arity.t = with | Submodule subs -> subs.(m) (* TODO: shall we store it as array?*) | Single _ -> Lam_arity.na) - | Lprim {primitive = Praw_js_code {code_info = Exp (Js_function {arity})}} -> - Lam_arity.info [arity] false | Lprim {primitive = Praise; _} -> Lam_arity.raise_arity_info | Lglobal_module _ (* TODO: fix me never going to happen *) | Lprim _ -> Lam_arity.na (* CHECK*) diff --git a/compiler/core/lam_pass_collect.ml b/compiler/core/lam_pass_collect.ml index 5f4a0d46e5..7e1b2dfcd2 100644 --- a/compiler/core/lam_pass_collect.ml +++ b/compiler/core/lam_pass_collect.ml @@ -64,13 +64,6 @@ let collect_info (meta : Lam_stats.t) (lam : Lam.t) = | Lprim {primitive = Psome | Psome_not_nest; args = [v]} -> Hash_ident.replace meta.ident_tbl ident (Normal_optional v); collect v - | Lprim - { - primitive = Praw_js_code {code_info = Exp (Js_function {arity})}; - args = _; - } -> - Hash_ident.replace meta.ident_tbl ident - (FunctionId {arity = Lam_arity.info [arity] false; lambda = None}) | Lprim {primitive = Pnull_to_opt; args = [(Lvar _ as l)]; _} -> Hash_ident.replace meta.ident_tbl ident (OptionalBlock (l, Null)) | Lprim {primitive = Pundefined_to_opt; args = [(Lvar _ as l)]; _} -> diff --git a/tests/tests/src/raw_arity.mjs b/tests/tests/src/raw_arity.mjs new file mode 100644 index 0000000000..e7ebe48da4 --- /dev/null +++ b/tests/tests/src/raw_arity.mjs @@ -0,0 +1,11 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +let foo = (function add(x, y=5){ return x + y }); + +console.log(foo(2)); + +export { + foo, +} +/* Not a pure module */ diff --git a/tests/tests/src/raw_arity.res b/tests/tests/src/raw_arity.res new file mode 100644 index 0000000000..39d7c62d5e --- /dev/null +++ b/tests/tests/src/raw_arity.res @@ -0,0 +1,3 @@ +let foo: int => int = %raw(`function add(x, y=5){ return x + y }`) + +Console.log(foo(2))