:wave: Hi team! I want to use the `kotlin("compile...
# compiler
t
👋 Hi team! I want to use the
kotlin("compiler-embeddable")
version
1.8.2x
to access
FIR
elements in a Java app and get a
bad class file
error during compilation. I can use classes like
FirPrimaryConstructor
on version
1.8.0
, an error occurs starting on version
1.8.2x
. I created a simple project that reproduces the error here. Any helps is greatly appreciated, thanks in advance!
Error:
Copy code
/Users/yoshi/Desktop/kotlin-example/src/main/java/org/example/Main.java:3: error: cannot access FirPrimaryConstructor
import org.jetbrains.kotlin.fir.declarations.impl.FirPrimaryConstructor;
                                                 ^
  bad class file: /Users/yoshi/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-compiler-embeddable/1.8.22/e2cf111da088dc807a74157741b4cd4b664edfb7/kotlin-compiler-embeddable-1.8.22.jar(/org/jetbrains/kotlin/fir/declarations/impl/FirPrimaryConstructor.class)
    undeclared type variable: T
    Please remove or make sure it appears in the correct subdirectory of the classpath.
d
Could you please report an issue about it? This problem looks very weird
As a workaround you can just write everything in Kotlin
Copy code
fun test(obj: Any?) {
    if (obj is FirPrimaryConstructor) {
        println("hello")
    }
}
I checked, it works just fine
t
Yes, it’s a strange error, I created an issue here: https://youtrack.jetbrains.com/issue/KT-59616/Java-compilation-error-Bad-class-file-while-using-FIR-tree-in-Java Ya, I’d expect many failures on the backend if it didn’t work in Kotlin. I appreciate the option, I’ll check in with the team, thanks again!
@dmitriy.novozhilov, do you know how complex the issue is, have an estimate on prioritization, and/or how long it will be until a fix is available?
d
Unfortunately I don't cc @udalov just in case
u
Thanks for bringing this up, I’ve answered in the issue.
@dmitriy.novozhilov FYI any introduction/usages of
@JvmInline
classes will make it difficult to use compiler internals from Java, even when bugs like KT-52706 are fixed. I believe we are OK with this, so it’s just something to remember.