Skip to content

Commit 88f7c1c

Browse files
committed
Fix #323
Kotlin reflect doesn't support synthetic classes, but we are OK with that ATM. So, we simply return false for the classes Kotlin reflect doesn't support. If you want to implement some renderer with a more complex logic, you can proceed with a Java reflection.
1 parent 64599d1 commit 88f7c1c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ class SubtypeRendererTypeHandler(private val superType: KClass<*>, override val
135135
}
136136

137137
override fun acceptsType(type: KClass<*>): Boolean {
138-
return type.isSubclassOf(superType)
138+
return try {
139+
type.isSubclassOf(superType)
140+
} catch (e: UnsupportedOperationException) {
141+
false
142+
}
139143
}
140144

141145
override fun replaceVariables(mapping: Map<String, String>): SubtypeRendererTypeHandler {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,18 @@ class ReplTests : AbstractSingleReplTest() {
443443

444444
assertEquals("org.RDKit.RWMol", res!!::class.qualifiedName)
445445
}
446+
447+
@Test
448+
fun testLambdaRendering() {
449+
val res = eval(
450+
"""
451+
val foo: (Int) -> Int = {it + 1}
452+
foo
453+
""".trimIndent()
454+
).resultValue!!
455+
@Suppress("UNCHECKED_CAST")
456+
assertEquals(2, (res as (Int) -> Int)(1))
457+
}
446458
}
447459

448460
class ReplVarsTest : AbstractSingleReplTest() {

0 commit comments

Comments
 (0)