diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.java index 9a5491f4f7c..01f6752101d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.java @@ -158,7 +158,7 @@ public class ScriptCodegen extends MemberCodegen { iv.load(0, classType); - int valueParamStart = context.getEarlierScripts().size() + 1; + int valueParamStart = context.getEarlierScripts().isEmpty() ? 1 : 2; // this + array of earlier scripts if not empty List valueParameters = scriptDescriptor.getUnsubstitutedPrimaryConstructor().getValueParameters(); for (ValueParameterDescriptor superclassParam: ctorDesc.getValueParameters()) { @@ -185,18 +185,20 @@ public class ScriptCodegen extends MemberCodegen { FrameMap frameMap = new FrameMap(); frameMap.enterTemp(OBJECT_TYPE); - for (ScriptDescriptor importedScript : context.getEarlierScripts()) { - frameMap.enter(importedScript, OBJECT_TYPE); - } - int offset = 1; + if (!context.getEarlierScripts().isEmpty()) { + int scriptsParamIndex = frameMap.enterTemp(AsmUtil.getArrayType(OBJECT_TYPE)); - for (ScriptDescriptor earlierScript : context.getEarlierScripts()) { - Type earlierClassType = typeMapper.mapClass(earlierScript); - iv.load(0, classType); - iv.load(offset, earlierClassType); - offset += earlierClassType.getSize(); - iv.putfield(classType.getInternalName(), context.getScriptFieldName(earlierScript), earlierClassType.getDescriptor()); + int earlierScriptIndex = 0; + for (ScriptDescriptor earlierScript : context.getEarlierScripts()) { + Type earlierClassType = typeMapper.mapClass(earlierScript); + iv.load(0, classType); + iv.load(scriptsParamIndex, earlierClassType); + iv.aconst(earlierScriptIndex++); + iv.aload(OBJECT_TYPE); + iv.checkcast(earlierClassType); + iv.putfield(classType.getInternalName(), context.getScriptFieldName(earlierScript), earlierClassType.getDescriptor()); + } } ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, methodContext, state, this); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java index 656de027dc7..9600ba02965 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java @@ -1477,8 +1477,8 @@ public class KotlinTypeMapper { sw.writeParametersStart(); - for (ScriptDescriptor importedScript : importedScripts) { - writeParameter(sw, importedScript.getDefaultType(), /* callableDescriptor = */ null); + if (importedScripts.size() > 0) { + writeParameter(sw, DescriptorUtilsKt.getModule(script).getBuiltIns().getArray().getDefaultType(), null); } for (ValueParameterDescriptor valueParameter : script.getUnsubstitutedPrimaryConstructor().getValueParameters()) { diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/GenericReplEvaluator.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/GenericReplEvaluator.kt index dc5c6fccc0b..f1c979e0aa8 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/GenericReplEvaluator.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/GenericReplEvaluator.kt @@ -74,10 +74,14 @@ open class GenericReplEvaluator(val baseClasspath: Iterable, val useScriptArgs = currentScriptArgs?.scriptArgs val useScriptArgsTypes = currentScriptArgs?.scriptArgsTypes?.map { it.java } - val constructorParams: Array> = (historyActor.effectiveHistory.map { it.klass.java } + - (useScriptArgs?.mapIndexed { i, it -> useScriptArgsTypes?.getOrNull(i) ?: it?.javaClass ?: Any::class.java } ?: emptyList()) - ).toTypedArray() - val constructorArgs: Array = (historyActor.effectiveHistory.map { it.instance } + useScriptArgs.orEmpty()).toTypedArray() + val hasHistory = historyActor.effectiveHistory.isNotEmpty() + + val constructorParams: Array> = (if (hasHistory) arrayOf>(Array::class.java) else emptyArray>()) + + (useScriptArgs?.mapIndexed { i, it -> useScriptArgsTypes?.getOrNull(i) ?: it?.javaClass ?: Any::class.java } ?: emptyList()) + + val constructorArgs: Array = if (hasHistory) arrayOf(historyActor.effectiveHistory.map { it.instance }.takeIf { it.isNotEmpty() }?.toTypedArray(), + *(useScriptArgs.orEmpty())) + else useScriptArgs.orEmpty() // TODO: try/catch ? val scriptInstanceConstructor = scriptClass.getConstructor(*constructorParams) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplInterpreter.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplInterpreter.kt index 71a1d695552..4863432c81b 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplInterpreter.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplInterpreter.kt @@ -51,7 +51,7 @@ class ReplInterpreter( hasErrors = false } - override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) { + override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) { val msg = messageRenderer.render(severity, message, location) with (replConfiguration.writer) { when (severity) { diff --git a/compiler/tests/org/jetbrains/kotlin/cli/jvm/repl/GenericReplTest.kt b/compiler/tests/org/jetbrains/kotlin/cli/jvm/repl/GenericReplTest.kt index aaf425028f8..4f8f265945f 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/jvm/repl/GenericReplTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/cli/jvm/repl/GenericReplTest.kt @@ -146,15 +146,14 @@ class GenericReplTest : TestCase() { } } -// #KT-10060, TODO: fix and uncomment/rename -// @Test - fun ignored_test256Evals() { + @Test + fun test256Evals() { TestRepl().use { repl -> val state = repl.createState() repl.compileAndEval(state, ReplCodeLine(0, 0, "val x0 = 0")) - val evals = 255 + val evals = 256 for (i in 1..evals) { repl.compileAndEval(state, ReplCodeLine(i, 0, "val x$i = x${i-1} + 1")) }