Closed ghost closed 3 years ago
Hi, have same issue.
Working solution for me:
inline fun <reified T> createCustom(di: DI = customDi): T {
return doCreateCustom(di, T::class)
}
@Suppress("UNCHECKED_CAST")
fun <T: Any> doCreateCustom(di: DI, clazz: KClass<*>): T {
val something by di.Instance(erased(clazz))
return something as T
}
Hi.
This seems to be a Kotlin issue with the new JVM IR backend. In fact, you said it yourself, if you use Kodein-DI 7.6.0 built with kotlin 1.5, on a kotlin 1.4.32 project this is working fine. However, if you enable the JVM IR backend on your project with kotlin 1.4.32 you'll get the same error.
Using your repro project @zglrx99 here is my gradle config to get the error on Kotlin 1.4.32
plugins {
kotlin("jvm") version "1.4.32"
}
allprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
group = "org.example"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
api("org.kodein.di:kodein-di-jvm:7.6.0")
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "11"
kotlinOptions.useIR = true
}
}
version = "1.0-SNAPSHOT"
Also, you can drop an issue on Kotlin's issue tracker https://youtrack.jetbrains.com/issues.
Thank you for help, if you are interested, here new issue on youtrack - https://youtrack.jetbrains.com/issue/IDEA-272984
thanks. you should change the target of your issue, you've set it to IntelliJ IDEA m it should be Kotlin.
yea, i tried, but after creation it has restriction of target modification
moderator changed target, here new link - https://youtrack.jetbrains.com/issue/KTIJ-19026
Faced a problem when updating to kotlin 1.5.0, example below
Steps:
Result:
Expect:
No errors
That code will be work properly, if you downgrade plugin version of kotlin - https://github.com/zglrx99/test-illegal-access/blob/master/build.gradle.kts
plugins { kotlin("jvm") version "1.4.32" }