kotlin-compiler-server icon indicating copy to clipboard operation
kotlin-compiler-server copied to clipboard

Cannot inline bytecode built with JVM target 11 into bytecode that is being built with JVM target 1.8

Open sheu opened this issue 3 years ago • 3 comments

I cloned this project and added my own kotlin library that is compiled with java 11 as the target. I however cannot run code that requires fold operation based on the result of library operations. The server returns this error: "Cannot inline bytecode built with JVM target 11 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option"

What JVM target is used to the the code passed my /run endpoint?. How can I specify the jvm target for run calls?

sheu avatar Dec 05 '22 15:12 sheu

I think it's a duplicate. https://github.com/AlexanderPrendota/kotlin-compiler-server/issues/576.

Please rebase on master.

I hope it helps

AlexanderPrendota avatar Dec 05 '22 21:12 AlexanderPrendota

I rebased and I still come across this issue. I also updated the source compatibility but I still get the same error. Also looking at #576 I cannot figure out what upgrade was done to resolve the issue.

My understanding is that when a call to /run is made, the compiler server will compile and run the code. I think this is where the issue is because the default target is 1.8 if not specified.

I tried making this change in component/KotlinEnvironment.kt:

private val additionalCompilerArguments: List<String> = listOf(
      "-opt-in=kotlin.ExperimentalStdlibApi",
      "-opt-in=kotlin.time.ExperimentalTime",
      "-opt-in=kotlin.RequiresOptIn",
      "-opt-in=kotlin.ExperimentalUnsignedTypes",
      "-opt-in=kotlin.contracts.ExperimentalContracts",
      "-opt-in=kotlin.experimental.ExperimentalTypeInference",
      "-jvm-target 11",
      "-Xcontext-receivers",
      "-XXLanguage:+RangeUntilOperator"
    )

adding "-jvm-target 11", This did not help either. What am I missing ?

sheu avatar Dec 06 '22 10:12 sheu

After some debugging, I found out that the compiler configurations that is built in component/KotlinEnvironment.kt does not not include the jvm target and setting this in the additionalCompilerArguments does not help either.

The quick fix for me was to add the lines put(JVMConfigurationKeys.JVM_TARGET, JvmTarget.JVM_11) in the method createConfiguration()

Refer to #594

sheu avatar Jan 09 '23 23:01 sheu