Restore returning of functional types from repl eval
add tests for the broken case as well for the return value representation #KT-29490 fixed
This commit is contained in:
+1
-1
@@ -110,7 +110,7 @@ open class GenericReplEvaluator(
|
||||
|
||||
val resultFieldName = scriptResultFieldName(compileResult.lineId.no)
|
||||
val resultField = scriptClass.getDeclaredField(resultFieldName).apply { isAccessible = true }
|
||||
val resultValue: Any? = if (!compileResult.isFunctionType) resultField.get(scriptInstance) else "<function>"
|
||||
val resultValue: Any? = resultField.get(scriptInstance)
|
||||
|
||||
return if (compileResult.hasResult) ReplEvalResult.ValueResult(resultFieldName, resultValue, compileResult.type)
|
||||
else ReplEvalResult.UnitResult()
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
>>> { 1 + 2 }
|
||||
() -> kotlin.Int
|
||||
>>> val x = { "abc" }
|
||||
>>> x
|
||||
() -> kotlin.String
|
||||
@@ -84,6 +84,11 @@ public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest {
|
||||
runTest("compiler/testData/repl/functionReferencesPrev.repl");
|
||||
}
|
||||
|
||||
@TestMetadata("functionResult.repl")
|
||||
public void testFunctionResult() throws Exception {
|
||||
runTest("compiler/testData/repl/functionResult.repl");
|
||||
}
|
||||
|
||||
@TestMetadata("imports.repl")
|
||||
public void testImports() throws Exception {
|
||||
runTest("compiler/testData/repl/imports.repl");
|
||||
|
||||
+11
@@ -233,6 +233,17 @@ obj
|
||||
Assert.assertTrue("eval in eval is too long: ${times.joinToString { "(${it.first.ms()}, ${it.second.ms()})" }} (expecting no more than 5x difference)",
|
||||
adjustedMaxDiff.third < 20 /* assuming it measurement error */ || adjustedMaxDiff.first * 5 > adjustedMaxDiff.second )
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `kotlin script evaluation should support functional return types`() {
|
||||
val scriptEngine = KotlinJsr223JvmLocalScriptEngineFactory().scriptEngine
|
||||
|
||||
val script = "{1 + 2}"
|
||||
val result = scriptEngine.eval(script)
|
||||
|
||||
Assert.assertTrue(result is Function0<*>)
|
||||
Assert.assertEquals(3, (result as Function0<*>).invoke())
|
||||
}
|
||||
}
|
||||
|
||||
fun assertThrows(exceptionClass: Class<*>, body: () -> Unit) {
|
||||
|
||||
Reference in New Issue
Block a user