Fix parameter index on IR script generation in REPL scenario
Before it, the wrong index lead to the validation error when repl script definition had c-tor parameters (see test)
This commit is contained in:
@@ -79,7 +79,7 @@ class ScriptGenerator(declarationGenerator: DeclarationGenerator) : DeclarationG
|
|||||||
// This is part of a hack for implicit receivers that converted to value parameters below
|
// This is part of a hack for implicit receivers that converted to value parameters below
|
||||||
// The proper schema would be to get properly indexed parameters from frontend (descriptor.implicitReceiversParameters),
|
// The proper schema would be to get properly indexed parameters from frontend (descriptor.implicitReceiversParameters),
|
||||||
// but it seems would require a proper remapping for the script body
|
// but it seems would require a proper remapping for the script body
|
||||||
// TODO: implement implicit receiver parameters handlin properly
|
// TODO: implement implicit receiver parameters handling properly
|
||||||
var parametersIndex = 0
|
var parametersIndex = 0
|
||||||
|
|
||||||
irScript.earlierScripts = context.extensions.getPreviousScripts()?.filter {
|
irScript.earlierScripts = context.extensions.getPreviousScripts()?.filter {
|
||||||
@@ -101,8 +101,13 @@ class ScriptGenerator(declarationGenerator: DeclarationGenerator) : DeclarationG
|
|||||||
}
|
}
|
||||||
|
|
||||||
irScript.explicitCallParameters = descriptor.explicitConstructorParameters.map { valueParameterDescriptor ->
|
irScript.explicitCallParameters = descriptor.explicitConstructorParameters.map { valueParameterDescriptor ->
|
||||||
parametersIndex++
|
context.irFactory.createValueParameter(
|
||||||
valueParameterDescriptor.toIrValueParameter(startOffset, endOffset, IrDeclarationOrigin.SCRIPT_CALL_PARAMETER).also { it.parent = irScript }
|
startOffset, endOffset, IrDeclarationOrigin.SCRIPT_CALL_PARAMETER, IrValueParameterSymbolImpl(),
|
||||||
|
valueParameterDescriptor.name, parametersIndex++,
|
||||||
|
valueParameterDescriptor.type.toIrType(), valueParameterDescriptor.varargElementType?.toIrType(),
|
||||||
|
valueParameterDescriptor.isCrossinline, valueParameterDescriptor.isNoinline,
|
||||||
|
false, false
|
||||||
|
).also { it.parent = irScript }
|
||||||
}
|
}
|
||||||
|
|
||||||
irScript.implicitReceiversParameters = descriptor.implicitReceivers.map {
|
irScript.implicitReceiversParameters = descriptor.implicitReceivers.map {
|
||||||
|
|||||||
+22
@@ -16,6 +16,8 @@ import kotlin.script.experimental.jvm.BasicJvmReplEvaluator
|
|||||||
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
||||||
import kotlin.script.experimental.jvm.updateClasspath
|
import kotlin.script.experimental.jvm.updateClasspath
|
||||||
import kotlin.script.experimental.jvm.util.classpathFromClass
|
import kotlin.script.experimental.jvm.util.classpathFromClass
|
||||||
|
import kotlin.script.experimental.jvmhost.createJvmScriptDefinitionFromTemplate
|
||||||
|
import kotlin.script.templates.standard.ScriptTemplateWithArgs
|
||||||
|
|
||||||
class ReplTest : TestCase() {
|
class ReplTest : TestCase() {
|
||||||
|
|
||||||
@@ -231,6 +233,26 @@ class ReplTest : TestCase() {
|
|||||||
assertTrue("Refinement handler on annotation is not invoked", handlerInvoked)
|
assertTrue("Refinement handler on annotation is not invoked", handlerInvoked)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testDefinitionWithConstructorArgs() {
|
||||||
|
val scriptDef = createJvmScriptDefinitionFromTemplate<ScriptTemplateWithArgs>(
|
||||||
|
evaluation = {
|
||||||
|
constructorArgs(arrayOf("a"))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
checkEvaluateInRepl(
|
||||||
|
sequenceOf(
|
||||||
|
"args[0]",
|
||||||
|
"res0+args[0]",
|
||||||
|
"res1+args[0]"
|
||||||
|
),
|
||||||
|
sequenceOf("a", "aa", "aaa"),
|
||||||
|
scriptDef.compilationConfiguration,
|
||||||
|
scriptDef.evaluationConfiguration
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private fun evaluateInRepl(
|
private fun evaluateInRepl(
|
||||||
snippets: Sequence<String>,
|
snippets: Sequence<String>,
|
||||||
|
|||||||
Reference in New Issue
Block a user