-
Notifications
You must be signed in to change notification settings - Fork 459
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
Don't emit f(undefined) when passing unit ()
.
#6459
Conversation
This changes code generation so it emits `f()` instead of `f(undefined)` when the function takes a single argument and its value is `undefined`.
I am very much in favor of removing the superfluous
This means that (an example from the PR changes) g.curr = Some(None) used to get compiled to g.curr = Caml_option.some(undefined); but is now g.curr = Caml_option.some(); This will still work, but somehow it goes against the meaning of the original ReScript code, as |
The current behavior caused an issue with emscripten-produced ffi code that ends up looking something like:
It's not currently possible with Rescript ffi bindings to produce an invocation to In general I agree with @cknitt that the presence of |
()
.
Added check so that only passing Still wondering if there are cases where this behaviour is undesirable, so we do know. Something where the number of arguments is counted explicitly on the callee site, and this behaviour is not the expected one. It's clear that any such case would be a corner case, but curious about what those corner cases are. One could argue that right now there's no way to pass a unit argument to a function of arity 1. The question is whether there's ever such a need. |
If it distinguishes unit then I can't think of any potential issue with this, at least not OTOH. Will mull on it a bit more. I'd say the resulting code from this is much more what I'd expect the output to be (omitting |
Co-authored-by: Christoph Knittel <ck@cca.io>
This changes code generation so it emits
f()
instead off(undefined)
when the function takes a single argument and its value isundefined
.Related companion PR: #6131
The current check distinguishes passing
()
vs passing e.g.undefined
, and omits the argument only in the former case.