Skip to content

Commit 24b8cc1

Browse files
committed
Fix #328: apply workaround for KT-48636
1 parent 5c7f017 commit 24b8cc1

File tree

7 files changed

+23
-3
lines changed

7 files changed

+23
-3
lines changed

build-plugin/src/build/BuildSettingsExtension.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class BuildSettingsExtension(private val project: Project) {
4949
fun skipPrereleaseCheck() = args.add("-Xskip-prerelease-check")
5050
fun requiresOptIn() = args.add("-Xopt-in=kotlin.RequiresOptIn")
5151
fun allowResultReturnType() = args.add("-Xallow-result-return-type")
52+
fun useOldBackend() = args.add("-Xuse-old-backend")
53+
54+
fun samConversions(type: String) = args.add("-Xsam-conversions=$type")
55+
fun samConversionsClass() = samConversions("class")
5256
}
5357

5458
fun withCompilerArgs(configure: KotlinCompilerArgsBuilder.() -> Unit) {

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ buildSettings {
7575
withLanguageLevel(rootSettings.kotlinLanguageLevel)
7676
withCompilerArgs {
7777
skipPrereleaseCheck()
78+
samConversionsClass()
7879
}
7980
withTests()
8081
}

jupyter-lib/api/src/main/kotlin/org/jetbrains/kotlinx/jupyter/api/Notebook.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ interface Notebook {
2222
*/
2323
val cellVariables: Map<Int, Set<String>>
2424

25+
/**
26+
* Returns the object that allows to access execution results
27+
*/
28+
val resultsAccessor: ResultsAccessor
29+
2530
/**
2631
* Mapping allowing to get cell by execution number
2732
*/

jupyter-lib/lib/src/main/kotlin/jupyter/kotlin/ScriptTemplateWithDisplayHelpers.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ abstract class ScriptTemplateWithDisplayHelpers(
3030
USE(o.getDefinitions(notebook).single())
3131
}
3232

33-
val Out: ResultsAccessor get() = ResultsAccessor { id ->
34-
notebook.getResult(id)
35-
}
33+
val Out: ResultsAccessor get() = notebook.resultsAccessor
3634

3735
val JavaRuntimeUtils get() = notebook.jreInfo
3836
}

src/main/kotlin/org/jetbrains/kotlinx/jupyter/apiImpl.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.jetbrains.kotlinx.jupyter.api.JREInfoProvider
99
import org.jetbrains.kotlinx.jupyter.api.KotlinKernelVersion
1010
import org.jetbrains.kotlinx.jupyter.api.Notebook
1111
import org.jetbrains.kotlinx.jupyter.api.RenderersProcessor
12+
import org.jetbrains.kotlinx.jupyter.api.ResultsAccessor
1213
import org.jetbrains.kotlinx.jupyter.api.VariableState
1314
import org.jetbrains.kotlinx.jupyter.repl.InternalEvaluator
1415

@@ -110,6 +111,8 @@ class NotebookImpl(
110111
override val cellVariables: Map<Int, Set<String>>
111112
get() = currentCellVariables
112113

114+
override val resultsAccessor = ResultsAccessor { getResult(it) }
115+
113116
override fun getCell(id: Int): CodeCellImpl {
114117
return cells[id] ?: throw ArrayIndexOutOfBoundsException(
115118
"There is no cell with number '$id'"

src/test/kotlin/org/jetbrains/kotlinx/jupyter/test/repl/ReplTests.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import kotlin.script.experimental.api.SourceCode
2424
import kotlin.test.assertEquals
2525
import kotlin.test.assertFails
2626
import kotlin.test.assertFalse
27+
import kotlin.test.assertNotNull
2728
import kotlin.test.fail
2829

2930
class ReplTests : AbstractSingleReplTest() {
@@ -455,6 +456,12 @@ class ReplTests : AbstractSingleReplTest() {
455456
@Suppress("UNCHECKED_CAST")
456457
assertEquals(2, (res as (Int) -> Int)(1))
457458
}
459+
460+
@Test
461+
fun testOutVarRendering() {
462+
val res = eval("Out").resultValue
463+
assertNotNull(res)
464+
}
458465
}
459466

460467
class ReplVarsTest : AbstractSingleReplTest() {

src/test/kotlin/org/jetbrains/kotlinx/jupyter/test/testUtil.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.jetbrains.kotlinx.jupyter.api.JREInfoProvider
1313
import org.jetbrains.kotlinx.jupyter.api.KotlinKernelVersion
1414
import org.jetbrains.kotlinx.jupyter.api.Notebook
1515
import org.jetbrains.kotlinx.jupyter.api.RenderersProcessor
16+
import org.jetbrains.kotlinx.jupyter.api.ResultsAccessor
1617
import org.jetbrains.kotlinx.jupyter.api.VariableState
1718
import org.jetbrains.kotlinx.jupyter.api.VariableStateImpl
1819
import org.jetbrains.kotlinx.jupyter.api.libraries.ExecutionHost
@@ -162,6 +163,7 @@ object NotebookMock : Notebook {
162163
get() = emptyList()
163164
override val variablesState = mutableMapOf<String, VariableStateImpl>()
164165
override val cellVariables = mapOf<Int, Set<String>>()
166+
override val resultsAccessor = ResultsAccessor { getResult(it) }
165167

166168
override fun getCell(id: Int): CodeCellImpl {
167169
return cells[id] ?: throw ArrayIndexOutOfBoundsException(

0 commit comments

Comments
 (0)