-
-
Notifications
You must be signed in to change notification settings - Fork 57
Closed
Description
Summary
OCaml source code:
let test3 () =
let open Samplelib.MonadOps(Promise) in
return 2
>>= fun x -> return (x + 40)
>>= fun x -> return (to_be (expect x) 42)
The generated JavaScript:
function test3(param) {
var open = Samplelib.MonadOps($$Promise$1);
var $great$great$eq = open[1];
var $$return = open[0];
return Curry._2($great$great$eq, Curry._1($$return, 2), (function (x) {
return Curry._2($great$great$eq, Curry._1($$return, x + 40 | 0), (function (x) {
return Curry._1($$return, (expect(x).toBe(42), undefined));
}));
}));
}
Test result:
FAIL test/samplelib.test.js
✓ it loads (2 ms)
✓ test1 (1 ms)
✓ test2
✕ test3 (1 ms)
● test3
TypeError: Cannot read properties of undefined (reading 'length')
43 | var $great$great$eq = open[1];
44 | var $$return = open[0];
> 45 | return Curry._2($great$great$eq, Curry._1($$return, 2), (function (x) {
| ^
46 | return Curry._2($great$great$eq, Curry._1($$return, x + 40 | 0), (function (x) {
47 | return Curry._1($$return, (expect(x).toBe(42), undefined));
48 | }));
at Object._1 (_output/node_modules/melange.runtime/curry.js:31:17)
at Object._1 [as test3] (_output/samplelib_test.js:45:42)
at Object.test3 (test/samplelib.test.js:17:29)
This is a reproduction repository:
https://github.com/kxc-wraikny/Melange_bug
Details
The functor is defined as
module MonadOps(M : sig
type _ t
val return : 'x -> 'x t
val bind : 'x t -> ('x -> 'y t) -> 'y t
end) = struct
let return = M.return
let (>>=) = M.bind
end
and this is the test code and the problem occurs at test3
module Test = struct
let test1 () =
let open Promise in
return 2
|> flip bind (fun x -> return (x + 40))
|> flip bind @@ fun x -> return (to_be (expect x) 42)
let test2 () =
let module M = Samplelib.MonadOps(Promise) in
let open M in
return 2
>>= fun x -> return (x + 40)
>>= fun x -> return (to_be (expect x) 42)
let test3 () =
let open Samplelib.MonadOps(Promise) in
return 2
>>= fun x -> return (x + 40)
>>= fun x -> return (to_be (expect x) 42)
end
The generated code:
function test1(param) {
var m = Promise.resolve(2);
var m$1 = m.then(function (x) {
return Promise.resolve(x + 40 | 0);
});
return m$1.then(function (x) {
return Promise.resolve((expect(x).toBe(42), undefined));
});
}
function test2(param) {
var M = Samplelib.MonadOps($$Promise$1);
return Curry._2(M.$great$great$eq, Curry._1(M.$$return, 2), (function (x) {
return Curry._2(M.$great$great$eq, Curry._1(M.$$return, x + 40 | 0), (function (x) {
return Curry._1(M.$$return, (expect(x).toBe(42), undefined));
}));
}));
}
function test3(param) {
var open = Samplelib.MonadOps($$Promise$1);
var $great$great$eq = open[1];
var $$return = open[0];
return Curry._2($great$great$eq, Curry._1($$return, 2), (function (x) {
return Curry._2($great$great$eq, Curry._1($$return, x + 40 | 0), (function (x) {
return Curry._1($$return, (expect(x).toBe(42), undefined));
}));
}));
}
Metadata
Metadata
Assignees
Labels
No labels