JS: inliner supports extra argument caused by suspend conversions

This commit is contained in:
Anton Bannykh
2020-05-09 17:38:33 +03:00
parent ed8efafa9b
commit bdca4b45bd
2 changed files with 9 additions and 2 deletions
@@ -2,7 +2,6 @@
// WITH_RUNTIME // WITH_RUNTIME
// WITH_COROUTINES // WITH_COROUTINES
// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS
import helpers.* import helpers.*
import kotlin.coroutines.* import kotlin.coroutines.*
@@ -46,9 +46,17 @@ private constructor(
} }
private fun process() { private fun process() {
val arguments = getArguments() var arguments = getArguments()
val parameters = getParameters() val parameters = getParameters()
if (arguments.size > parameters.size) {
// Due to suspend conversions it is possible to have an extra argument, e.g. `fn($this$)` for `function fn() {...}`
// In such cases all missing arguments for default parameters are passed as `void 0` explicitly.
// Thus it is safe to drop it.
assert(arguments.size == parameters.size + 1) { "arguments.size (${arguments.size}) may only exceed the parameters.size (${parameters.size}) by one and only in case of suspend conversions" }
arguments = arguments.subList(0, parameters.size)
}
removeDefaultInitializers(arguments, parameters, body) removeDefaultInitializers(arguments, parameters, body)
aliasArgumentsIfNeeded(namingContext, arguments, parameters, call.source) aliasArgumentsIfNeeded(namingContext, arguments, parameters, call.source)
renameLocalNames(namingContext, invokedFunction) renameLocalNames(namingContext, invokedFunction)