Kotlin / kotlin-jupyter

Kotlin kernel for Jupyter/IPython
Apache License 2.0
1.1k stars 105 forks source link

Back-end (JVM) Internal error: Failed to generate expression: KtNameReferenceExpression #345

Open holgerbrandl opened 2 years ago

holgerbrandl commented 2 years ago

Consider the following example image

This fails with

Back-end (JVM) Internal error: Failed to generate expression: KtNameReferenceExpression
File being compiled: (1,28) in Line_7.jupyter-kts
The root cause java.lang.UnsupportedOperationException was thrown at: org.jetbrains.kotlin.codegen.context.ConstructorContext.getOuterExpression(ConstructorContext.java:65)

See attached notebook (zipped because github does not allow ipynb attachments to tickets) for complete example.

RandomInit.ipynb.zip

This code is legit in a main

import kotlin.random.Random

fun main() {
    val rand = Random(10)
    rand.nextInt()

    data class Foo(val smthg: Int = rand.nextInt() )

    println(Foo())
}

Environment: Windows10 & Kotlin kernel v. 0.10.3.31, Kotlin v. 1.6.20-dev-3702

ileasile commented 2 years ago

Hi! It looks like a duplicate of #126. The same pattern val variable_inside_class = <some expression containing top-level declaration>