K2 Scripting: fix order of arguments processing

and base class handling:
Since in K2 we do not distinguish between script arguments taken from
the base class and provided properties, we need this extra functionality
to preserve the argument order of K1 scripts.
This is a temporary measure, since we're going to deprecate base class
usage at some point (KT-60449), so the relevant constructor arguments
should disappear too.
This commit is contained in:
Ilya Chernikov
2023-04-27 17:53:33 +02:00
committed by Space Team
parent 96bde033e1
commit 020a590df7
10 changed files with 46 additions and 8 deletions
@@ -239,6 +239,7 @@ class Fir2IrVisitor(
}
if (isSelf) {
irScript.thisReceiver = irReceiver
irScript.baseClass = irReceiver.type
null
} else irReceiver
}
@@ -305,6 +305,10 @@ private class ScriptsToClassesLowering(val context: JvmBackendContext, val inner
} else {
+irDelegatingConstructorCall(baseClassCtor).also {
explicitParameters.forEachIndexed { idx, valueParameter ->
// Since in K2 we're not distinguishing between base class ctor args and other script args, we need this check.
// The logic is fragile, but since we plan to deprecate baseClass support (see KT-60449), and this delegating
// call will go away, let's leave it as is for now
if (idx >= it.valueArgumentsCount) return@forEachIndexed
it.putValueArgument(
idx,
IrGetValueImpl(