Compiler errors inlining functions after switching from Kotlin 1.0.x to 1.1


#1

I recently switched my project from Kotlin 1.0.6 to 1.1.1 and the compiler is now failing to inline almost every inline function I have. This is the error I get:

e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'method' into

Then I get something really strange about not being able to inline bytecode above version 50:

Cause: Not generated
Cause: Cannot inline bytecode of class which has version 52. This compiler can only inline Java 1.6 bytecode (version 50)

In my build file I have tried with and without:

compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

Same result either way. Not sure what to try here, any suggestions? Once again I want to make clear this exact same code had no issue compiling before 1.1, edit aside from the version of Kotlin stdlib being used.


#2

OK I forgot to try with and without the jre8 version of Kotlin stdlib. Turns out this is what’s causing the issue as one might assume from the compiler error output. Can someone explain what’s going on here? Can I really not use inline functions when targeting Java 8?


#3

You can use inline function from the library which was compiled for jvmTarget 1.8, only if you compile your code also with jvmTarget 1.8.

I see that you’ve tried to set that option, but maybe the usage of an inline function was in the different module (for example in tests)?


#4

Yes the problem is coming from usage of the method in tests, thanks. I don’t know how to resolve it though, do I
testCompile "org.jetbrains.kotlin:kotlin-test-jre8:$kotlin_version"
or something similair? Sorry I’m not very good with Gradle.


#5

In addition to what you already have, you need to set the JVM target for the compileTestKotlin task:

compileTestKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }  
}

#6

You also can set kotlinOptions for all kotlin tasks in gradle project with the following construction:

        tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }

#7

I encountered this issue with Eclipse and Kotlin plug-in

Is there a way to set this option for Eclipse plug-in somehow? I see that preferences page is empty for Kotlin / Compiler

Thanks!