i think i've come across a bug with 1.9.10 when ta...
# compiler
n
i think i've come across a bug with 1.9.10 when targeting JS. it seems related to nested scopes. this is the stack trace i'm seeing. and a minimum bit of code that reproduces it. wanted to check here to see if anyone knows of an open issue related to this before filing a new bug.
Copy code
Details: Internal error in body lowering: java.lang.IllegalStateException: No dispatch receiver parameter for FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Unit
	at org.jetbrains.kotlin.backend.common.lower.LocalDeclarationsLowering$LocalClassMemberContext.irGet(LocalDeclarationsLowering.kt:246)
	...
Caused by: java.lang.IllegalStateException: No dispatch receiver parameter for FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Unit
	... 147 more
Copy code
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

interface Context<T> {
    fun completed(result: T)
}

interface Api {
    suspend operator fun <T> invoke(contents: Context<T>.() -> Unit): T
}

open class Block

fun doSomething(lambda: () -> Unit) {}

class CompilerBug(api: Api, appScope: CoroutineScope) {
    init {
        // works when run not used
        run {
            appScope.launch {
                api<Boolean> {
                    // works when apply bock used
                    Block().apply {
                        doSomething { completed(true) }
                    }

                    // fails with run and init
                    object: Block() {
                        init {
                            doSomething { completed(true) }
                        }
                    }
                }
            }
        }
    }
}
Copy code
plugins {
    kotlin("js") version "1.9.10"
}

repositories {
    mavenCentral()
}

kotlin {
    js(IR) {
        browser {}
        binaries.executable()
    }

    dependencies {
        implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
    }
}
d
Please report an issue
n
done: KT-61929
d
Thank you!