Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not use object expresssions #341

Closed
holgerbrandl opened this issue Nov 2, 2021 · 7 comments
Closed

Can not use object expresssions #341

holgerbrandl opened this issue Nov 2, 2021 · 7 comments
Labels
bug Installation and functionality issues

Comments

@holgerbrandl
Copy link
Contributor

Consider the following example

val sim = object : ArrayList<String>() {
}

When using sim in a second code-cell this fails with:

Enclosing constructor not found
java.lang.InternalError: Enclosing constructor not found
	at java.base/java.lang.Class.getEnclosingConstructor(Class.java:1447)
	at kotlin.reflect.jvm.internal.impl.descriptors.runtime.structure.ReflectClassUtilKt.getClassId(reflectClassUtil.kt:62)
	at kotlin.reflect.jvm.internal.RuntimeTypeMapper.mapJvmClassToKotlinClassId(RuntimeTypeMapper.kt:272)
	at kotlin.reflect.jvm.internal.KClassImpl.getClassId(KClassImpl.kt:186)
	at kotlin.reflect.jvm.internal.KClassImpl.access$getClassId(KClassImpl.kt:44)
	at kotlin.reflect.jvm.internal.KClassImpl$Data$descriptor$2.invoke(KClassImpl.kt:49)
	at kotlin.reflect.jvm.internal.KClassImpl$Data$descriptor$2.invoke(KClassImpl.kt:48)
	at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke(ReflectProperties.java:93)
	at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:32)
	at kotlin.reflect.jvm.internal.KClassImpl$Data.getDescriptor(KClassImpl.kt:48)
	at kotlin.reflect.jvm.internal.KClassImpl$Data$supertypes$2.invoke(KClassImpl.kt:125)
	at kotlin.reflect.jvm.internal.KClassImpl$Data$supertypes$2.invoke(KClassImpl.kt:124)
	at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke(ReflectProperties.java:93)
	at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:32)
	at kotlin.reflect.jvm.internal.KClassImpl$Data.getSupertypes(KClassImpl.kt:124)
	at kotlin.reflect.jvm.internal.KClassImpl.getSupertypes(KClassImpl.kt:254)
	at kotlin.reflect.full.KClasses.getSuperclasses(KClasses.kt:184)
	at kotlin.reflect.full.KClasses$isSubclassOf$1.get(KClasses.kt:233)
	at kotlin.jvm.internal.PropertyReference1.invoke(PropertyReference1.java:35)
	at kotlin.reflect.full.KClasses$sam$org_jetbrains_kotlin_utils_DFS_Neighbors$0.getNeighbors(KClasses.kt)
	at kotlin.reflect.jvm.internal.impl.utils.DFS.doDfs(DFS.java:98)
	at kotlin.reflect.jvm.internal.impl.utils.DFS.dfs(DFS.java:27)
	at kotlin.reflect.jvm.internal.impl.utils.DFS.dfs(DFS.java:37)
	at kotlin.reflect.jvm.internal.impl.utils.DFS.ifAny(DFS.java:47)
	at kotlin.reflect.full.KClasses.isSubclassOf(KClasses.kt:233)
	at org.jetbrains.kotlinx.jupyter.util.ReflectonKt.isSubclassOfCatching(reflecton.kt:9)
	at org.jetbrains.kotlinx.jupyter.api.SubtypeRendererTypeHandler.acceptsType(renderersHandling.kt:138)
	at org.jetbrains.kotlinx.jupyter.api.RendererTypeHandler$DefaultImpls.accepts(renderersHandling.kt:62)
	at org.jetbrains.kotlinx.jupyter.api.PrecompiledRendererTypeHandler$DefaultImpls.accepts(renderersHandling.kt)
	at org.jetbrains.kotlinx.jupyter.api.SubtypeRendererTypeHandler.accepts(renderersHandling.kt:117)
	at org.jetbrains.kotlinx.jupyter.codegen.RenderersProcessorImpl.renderResult(RenderersProcessorImpl.kt:20)
	at org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl$evalEx$1$rendered$1$1.invoke(repl.kt:432)
	at org.jetbrains.kotlinx.jupyter.config.LoggingKt.catchAll(logging.kt:41)
	at org.jetbrains.kotlinx.jupyter.config.LoggingKt.catchAll$default(logging.kt:40)
	at org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl$evalEx$1.invoke(repl.kt:431)
	at org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl$evalEx$1.invoke(repl.kt:408)
	at org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl.withEvalContext(repl.kt:372)
	at org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl.evalEx(repl.kt:408)
	at org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl.eval(repl.kt:456)
	at org.jetbrains.kotlinx.jupyter.ProtocolKt$shellMessagesHandler$res$1.invoke(protocol.kt:290)
	at org.jetbrains.kotlinx.jupyter.ProtocolKt$shellMessagesHandler$res$1.invoke(protocol.kt:289)
	at org.jetbrains.kotlinx.jupyter.JupyterConnection$runExecution$execThread$1.invoke(connection.kt:166)
	at org.jetbrains.kotlinx.jupyter.JupyterConnection$runExecution$execThread$1.invoke(connection.kt:164)
	at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)

image

Since object expressions are a very useful tool when prototyping (i.e. working with notebooks), it would be most wonderful if this language feature could be fixed/enabled for the kernel.

Used kernel version: Kotlin kernel v. 0.10.3.20, Kotlin v. 1.6.20-dev-3702

@ileasile ileasile added the bug Installation and functionality issues label Nov 2, 2021
@altavir
Copy link
Contributor

altavir commented Nov 2, 2021

ileasile added a commit that referenced this issue Nov 2, 2021
@ileasile
Copy link
Contributor

ileasile commented Nov 2, 2021

@holgerbrandl thanks for reporting! It seems to be one more problem of scripts code generation, but can be easily workarounded on kernel side. I'll try to provide a better solution on scripting side later.

@ileasile
Copy link
Contributor

ileasile commented Nov 2, 2021

The downside of this workaround is that if you have defined a renderer for type A, and defined anonymous object object : A() {}, it will not be rendered with A's renderer.

@ileasile
Copy link
Contributor

ileasile commented Nov 2, 2021

@holgerbrandl @altavir try updating to 0.10.3.31

@altavir
Copy link
Contributor

altavir commented Nov 2, 2021

Works in DataLore on 0.10.3.31.

@ileasile
Copy link
Contributor

ileasile commented Nov 2, 2021

Just to remember: reproducer in Kotlin JvmReplTest:

fun testAnonymousObjectReflection() {
    JvmTestRepl()
        .use { repl ->
            assertEvalResult(repl, "42", 42)
            assertEvalUnit(repl, "val sim = object : ArrayList<String>() {}")

            val compiledSnippet = checkCompile(repl, "sim")
            val evalResult = repl.eval(compiledSnippet!!)

            val a = (evalResult.valueOrThrow().get().result as ResultValue.Value).value!!
            assertTrue(a::class.isSubclassOf(Any::class))
        }
}

@holgerbrandl
Copy link
Contributor Author

Works like charm now. Thank you so much for your great and blazingly fast support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Installation and functionality issues
Projects
None yet
Development

No branches or pull requests

3 participants