Skip to content

Commit b21c81d

Browse files
committed
Test: ignore inferred arity in case of %raw.
The inferred arity of raw JS code is actively used with `%ffi`, but it can produce unexpected results with `%raw`: ``` let foo: int => int = %raw(`function add(x, y=5){ return x + y }`) Console.log(foo(2)) ```
1 parent 05be83f commit b21c81d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

compiler/core/lam_arity_analysis.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ let rec get_arity (meta : Lam_stats.t) (lam : Lam.t) : Lam_arity.t =
6969
with
7070
| Submodule subs -> subs.(m) (* TODO: shall we store it as array?*)
7171
| Single _ -> Lam_arity.na)
72-
| Lprim {primitive = Praw_js_code {code_info = Exp (Js_function {arity})}} ->
72+
| Lprim {primitive = Praw_js_code {code_info = Exp (Js_function {arity})}}
73+
when false ->
7374
Lam_arity.info [arity] false
7475
| Lprim {primitive = Praise; _} -> Lam_arity.raise_arity_info
7576
| Lglobal_module _ (* TODO: fix me never going to happen *) | Lprim _ ->

compiler/core/lam_pass_collect.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ let collect_info (meta : Lam_stats.t) (lam : Lam.t) =
6868
{
6969
primitive = Praw_js_code {code_info = Exp (Js_function {arity})};
7070
args = _;
71-
} ->
71+
}
72+
when false ->
7273
Hash_ident.replace meta.ident_tbl ident
7374
(FunctionId {arity = Lam_arity.info [arity] false; lambda = None})
7475
| Lprim {primitive = Pnull_to_opt; args = [(Lvar _ as l)]; _} ->

0 commit comments

Comments
 (0)