-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Default values for function args breaks currying #983
Comments
Accidentally submitted the issue too soon, edited it to not just be a scratchpad of me collecting my thoughts :) |
@johnhaley81 I think the playground example is lacking type annotations, because the returned type from I tried to reproduce the problem in #984 but without success. Whenever the type is defined in the Js.t value properly, the generated code will be ok and there won't be any warnings. What I found is that I'm not able to put the |
There are a few things going on here: Reason -> OCaml translation
this is because you wrote the example in OCaml, and the translation wasn't faithful to the Reason counterpart. This, for example, triggers the alert: let props =
[%mel.raw
{|
{
foo: function(a, b) {
console.log("a", a);
console.log("b", b);
}
}
|}]
let () = (props##foo 123 "abc" [@u])
(* Here, the alert isn't triggered: *)
(* let () = (props##foo [@u]) 123 "abc" *) Default argumentsI couldn't find anything special about default arguments in the JS values. I'd appreciate if you could also include a repro here that triggers some kind of bug. For example, this snippet prints the expected values: let props =
[%mel.raw
{|
{
foo: function(a, b="b") {
console.log("a", a);
console.log("b", b);
}
}
|}]
let () = props##foo 123 output:
|
But in this case, as I mentioned above, the type of |
I'm not sure. I think you are correct but I didn't get a chance to investigate that yet! |
The playground comes very handy to debug this sort of thing. Indeed it's the case that the type inferred by It then gets inferred at application time of In this case, |
Sorry for the delayed response. I also looked into this further and it seems that this isn't a bug in Melange, but rather in how the ES6 is being transpiled which is causing the final JS code to somehow break currying in a way that I don't quite understand. Thanks for looking into it @anmonteiro and @jchavarri! |
I'm trying to call a function being passed to me in a
Js.t({..})
and it's not being called as I expected.ReasonML Code:
Function in JS Code side:
I think what is happening is the second arg
event
is being assigned a default value so when this function is called with a currying style that arg is not set properly.So now another interesting thing is, when I call the function in a uncurried way:
I get the following warning:
Which I believe is a false positive because in this situation the function is now called correctly!
So it seems that there are 2 main issues:
Js.t({..})
you'll get a warning about an unused attribute[@u]
(playground link)The text was updated successfully, but these errors were encountered: