https://kotlinlang.org logo
#javascript
Title
# javascript
e

Edoardo Luppi

03/01/2024, 6:59 PM
Given the following externals:
Copy code
typealias Done = (err: Any? /* use undefined for default */) -> Unit
typealias Func = (/* this: Context, */ done: Done) -> Unit

external class Test : Runnable {
  constructor(title: String, fn: Func)
}
And this usage:
Copy code
val fn: Func = {
  inst.example()
}
suite.addTest(Test("example", fn))
The outputted code for
val fn: Func
is:
Copy code
return function (it) {
  $inst.example_3o7jbu_k$();
  return Unit_getInstance();
};
Note the
it
argument is present even if it's not used. This is problematic when the JS code checks the number of arguments of the function. Should the JS compiler get rid of unused arguments like in this case?
j

jw

03/01/2024, 7:02 PM
Seems like you could make the exact same argument if unused arguments were removed, as it equally could affect usage where the number of arguments of a function are significant.
I don't really see how this would be possible especially in the presence of separate compilation units for those things. Seems like you should define another lambda signature which has zero arguments.
e

Edoardo Luppi

03/01/2024, 7:05 PM
An additional lambda signature was my second option since there are many of them with this issue. But you're right, removing or not an argument should probably be an explicit choice, done by whoever writes the external declarations.
Btw, with additional signatures you end up with a lot of
OVERLOAD_RESOLUTION_AMBIGUITY
errors.