I tried to change in my project Kotlin 1.4.32 and ...
# compose-desktop
v
I tried to change in my project Kotlin 1.4.32 and Compose build190 to Kotlin 1.5.0 and Compose build210... When I rebuild my project I receive Internal compiler error (look in the thread). I tried other earlier builds including build198 with Kotlin 1.4.32 and had the same error. When I returned to build190, error disappeared. What should I do to upgrade to the newer builds?
Copy code
java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
	at java.base/java.util.Objects.checkIndex(Objects.java:359)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at org.jetbrains.kotlin.ir.util.IrUtilsKt.getTypeSubstitutionMap(IrUtils.kt:540)
	at org.jetbrains.kotlin.ir.util.IrUtilsKt.getTypeSubstitutionMap(IrUtils.kt:554)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitCall(IrComposableAnnotator.kt:116)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitCall(IrElementVisitorVoid.kt:165)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitCall(IrComposableAnnotator.kt:60)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitCall(IrComposableAnnotator.kt:60)
	at org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl.accept(IrCallImpl.kt:47)
	at org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl.acceptChildren(IrVariableImpl.kt:77)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoidKt.acceptChildrenVoid(IrElementVisitorVoid.kt:275)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitElement(IrComposableAnnotator.kt:229)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitDeclaration(IrElementVisitorVoid.kt:40)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitDeclaration(IrComposableAnnotator.kt:215)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitVariable(IrElementVisitorVoid.kt:68)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitVariable(IrComposableAnnotator.kt:60)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitVariable(IrElementVisitorVoid.kt:69)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitVariable(IrComposableAnnotator.kt:60)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitVariable(IrComposableAnnotator.kt:60)
	at org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl.accept(IrVariableImpl.kt:74)
	at org.jetbrains.kotlin.ir.expressions.IrBlockBody.acceptChildren(IrBody.kt:57)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoidKt.acceptChildrenVoid(IrElementVisitorVoid.kt:275)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitElement(IrComposableAnnotator.kt:229)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitBody(IrElementVisitorVoid.kt:86)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitBody(IrComposableAnnotator.kt:192)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitBlockBody(IrElementVisitorVoid.kt:92)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitBlockBody(IrComposableAnnotator.kt:60)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitBlockBody(IrElementVisitorVoid.kt:93)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitBlockBody(IrComposableAnnotator.kt:60)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitBlockBody(IrComposableAnnotator.kt:60)
	at org.jetbrains.kotlin.ir.expressions.IrBlockBody.accept(IrBody.kt:54)
	at org.jetbrains.kotlin.ir.declarations.IrFunction.acceptChildren(IrFunction.kt:61)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoidKt.acceptChildrenVoid(IrElementVisitorVoid.kt:275)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitElement(IrComposableAnnotator.kt:229)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitDeclaration(IrElementVisitorVoid.kt:40)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitDeclaration(IrComposableAnnotator.kt:215)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitFunction(IrElementVisitorVoid.kt:49)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitFunction(IrComposableAnnotator.kt:81)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitSimpleFunction(IrElementVisitorVoid.kt:52)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitSimpleFunction(IrComposableAnnotator.kt:60)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitSimpleFunction(IrElementVisitorVoid.kt:53)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitSimpleFunction(IrComposableAnnotator.kt:60)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitSimpleFunction(IrComposableAnnotator.kt:60)
	at org.jetbrains.kotlin.ir.declarations.IrSimpleFunction.accept(IrSimpleFunction.kt:28)
	at org.jetbrains.kotlin.ir.declarations.IrClass.acceptChildren(IrClass.kt:60)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoidKt.acceptChildrenVoid(IrElementVisitorVoid.kt:275)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitElement(IrComposableAnnotator.kt:229)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitDeclaration(IrElementVisitorVoid.kt:40)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitDeclaration(IrComposableAnnotator.kt:215)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitClass(IrElementVisitorVoid.kt:43)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitClass(IrComposableAnnotator.kt:60)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitClass(IrElementVisitorVoid.kt:44)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitClass(IrComposableAnnotator.kt:60)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitClass(IrComposableAnnotator.kt:60)
	at org.jetbrains.kotlin.ir.declarations.IrClass.accept(IrClass.kt:55)
	at org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl.acceptChildren(IrFileImpl.kt:66)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoidKt.acceptChildrenVoid(IrElementVisitorVoid.kt:275)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitElement(IrComposableAnnotator.kt:229)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitPackageFragment(IrElementVisitorVoid.kt:30)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitPackageFragment(IrComposableAnnotator.kt:60)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitFile(IrElementVisitorVoid.kt:37)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitFile(IrComposableAnnotator.kt:60)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitFile(IrElementVisitorVoid.kt:38)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitFile(IrComposableAnnotator.kt:60)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotator.visitFile(IrComposableAnnotator.kt:60)
	at org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl.accept(IrFileImpl.kt:63)
	at org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl.acceptChildren(IrModuleFragmentImpl.kt:40)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoidKt.acceptChildrenVoid(IrElementVisitorVoid.kt:275)
	at androidx.compose.compiler.plugins.kotlin.lower.IrComposableAnnotatorKt.annotateComposableFunctions(IrComposableAnnotator.kt:56)
	at androidx.compose.compiler.plugins.kotlin.ComposeIrGenerationExtension.generate(ComposeIrGenerationExtension.kt:70)
	at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory$generateModule$1.invoke(JvmIrCodegenFactory.kt:93)
	at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory$generateModule$1.invoke(JvmIrCodegenFactory.kt:89)
	at org.jetbrains.kotlin.psi2ir.Psi2IrTranslator.generateModuleFragment(Psi2IrTranslator.kt:91)
	at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.generateModule(JvmIrCodegenFactory.kt:106)
	at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:35)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:595)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:211)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:154)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:169)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:88)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:386)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:110)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:286)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl$rebuild(IncrementalCompilerRunner.kt:99)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:114)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:74)
	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:607)
	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:96)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1659)
	at jdk.internal.reflect.GeneratedMethodAccessor42.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
	at java.base/java.lang.Thread.run(Thread.java:832)
j
Whenever I do major branch switches (for any project), I always blow away my gradle caches, because gradle is buggy as hell.
2
at the very least, a
./gradlew clean
and a
rm rf ~/.gradle
I also kill all the daemons associated with gradle (do a
jps -m
to find anything with the word Daemon in it)
v
@jim I made all these steps -nothing has changed :(
I have a complex porject with two Compose applications. These applications use shared libraries also present in this project. Some libraries have a dependency on Compose, some don't. To set versions of external packages in the project I use the buildSrc directory which has a src/main/kotlin/Deps.kt file of the following format:
Copy code
object Versions {
    const val kotlin = "1.5.0"
    const val compose = "0.4.0-build210"
    const val coroutines = "1.5.0"
    const val serialization = "1.2.0"

    // etc...
}

object Deps {
    object Kotlin {
        const val platform = "org.jetbrains.kotlin:kotlin-bom:${Versions.kotlin}"
        const val gradle_plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
        const val coroutines_core = "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:${Versions.coroutines}"
        const val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-json:${Versions.serialization}"
    }

    object Compose {
        const val gradle_plugin = "org.jetbrains.compose:compose-gradle-plugin:${Versions.compose}"
    }

    // etc...
}
File buildSrc/build.gradle.kts:
Copy code
repositories {
    mavenCentral()
    gradlePluginPortal()
}

plugins {
    `kotlin-dsl` apply true
}

File settings.gradle.kts in project directory have following format:

pluginManagement {
    repositories {
        jcenter()
        gradlePluginPortal()
        maven { url = uri("<https://maven.pkg.jetbrains.space/public/p/compose/dev>") }
    }
}

include(
    ":application1",
    ":application2",
    ":libs:lib1",
    ":libs:lib2",
    ":libs:lib3",
    // etc...
)
File build.gradle.kts in project directory:
Copy code
buildscript {
    repositories {
        mavenLocal().mavenContent {
            includeModule("org.jetbrains.compose", "compose-gradle-plugin")
        }
        google()
        jcenter()
        maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
    }

    dependencies {
        classpath("org.jetbrains.compose:compose-gradle-plugin:${Versions.compose}")
        classpath(kotlin("gradle-plugin", version = Versions.kotlin))
        classpath(kotlin("serialization", version = Versions.kotlin))
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
    }
}

subprojects {
    tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }
    tasks.withType<Test> {
        useJUnitPlatform()
    }
}
Each application has a build.gradle.kts file in its directory:
Copy code
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
    kotlin("jvm")
    kotlin("plugin.serialization")
    id("org.jetbrains.compose")
}

group = "..."
version = "..."

dependencies {
    implementation(compose.desktop.currentOs)
    implementation(Deps.Kotlin.serialization)
    implementation(Deps.Kotlin.coroutines_core)
    // etc...

    implementation(project(":libs:lib1"))
    implementation(project(":libs:lib2"))
    implementation(project(":libs:lib3"))
    // etc...
}

compose.desktop {
    application {
        mainClass = "project.application1.MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "Application1"
        }
    }
}
Each library from "libs" directory has a build.gradle.kts file in its directory:
Copy code
plugins {
    kotlin("jvm")
    kotlin("plugin.serialization")
    id("org.jetbrains.compose")
}

group = "..."
version = "..."

dependencies {
    implementation(compose.desktop.currentOs)
    implementation(Deps.Kotlin.serialization)
    // etc...

    implementation(project(":libs:lib2"))
    implementation(project(":libs:lib3"))
}
Or if the library does not depend on Compose:
Copy code
plugins {
    kotlin("jvm")
}

group = "..."
version = "..."

kotlin {
    dependencies {
        implementation(platform(Deps.Kotlin.platform))
        // etc...

        implementation(project(":libs:lib3"))
    }
}
j
Internal compile error is always a bug. If build190 worked and 198 breaks, it could be a regression in Kotlin since we recently upgraded major kotlin versions. If you can create+share a minimal repro, we can investigate further.
t
I have the same issue. It happened to me when upgrading Compose and other libraries to Kotlin 1.5. So it is hard to say what introduced this error. For me the issue was caused by some Kotlin code. The code is fine, it worked before, but for some reason it now causes this error. You should be able to see in the build log which gradle module has the issue. I have an abstract class with type parameters. That class was also extending another abstract class with type parameters. Another (final) class which extends the abstract class caused the error. When removing that class, or the type parameters completely, the error was gone for me. I think it is going to be quite difficult to make a minimal repo for this.
I found out the cause by just removing Kotlin files in the affected module until the project compiled. Then it was quite easy to just remove pieces of code in the affected file and that is how I found out the issue cause.
j
Even a non-minimal sample could be useful if you're able to share, although a minimal repro would be better :).
v
@Thomas I have the same case!
Copy code
abstract class A<Type1, Type2> {
  // ...
}

object C : A<Int, DataClass1> {
  // ...
}
This code works fine But when I add this code:
Copy code
abstract class B<Type3> : A<Int, Type3> {
  // ...
}

object D : B<DataClass2> {
  // ...
}

object E : B<DataClass3> {
 // ...
}
I get the internal compiler error...
I only uncommented сlass B without objects and got the same error
t
Great to hear you found the issue
v
I uncommented the class B in parts and checked when the error appears. If class A have open function:
Copy code
abstract class A<Type1, Type2> {
  open fun test(key: Type1) : Type2
  // ...
}
The error only appeared when I uncommented the overloaded function
Copy code
abstract class B<Type3> : A<Int, Type3> {
  override fun test(key: Int) : Type3 {
    // ...
    return super.test(key) // !!! The error occurs only when this line appears in the code !!!
  }
  // ...
}
@jim I can make minimal sample... Where is the best place to post this issue?
I make minimal sample with this error from Compose Desktop project template... When I try to use the same classes in Console Application project template - all works fine
t
Hmm can you try to add the kotlinx serialization dependency and plugin? Maybe that does something
I know that serialization had similar issues in the past but I do not know if it could be related.
Are you using Kotlin 1.5?
v
This error appears on Compose build198 with Kotlin 1.4.32, and on Compose build210 with Kotlin 1.5.0
t
Yes but are you using 1.5 in the minimal sample you are trying to create?
I'm going to try build198 in my project and see what happens.
v
In the console minimal sample I use Kotlin 1.5.10 and serialization 1.2.0. Also, I try Kotlin 1.4.32 and serialization 1.1.0 - also without errors. In the Compose minimal sample I use Kotlin 1.5.10 and Compose 0.4.0-rc2
I made a hack for my project:
Copy code
abstract class A<Type1, Type2> {
  protected fun makeTest(key: Type1): Type2 {
    //...
  }
  open fun test(key: Type1) : Type2 = makeTest(key)
}

abstract class B<Type3> : A<Int, Type3> {
  override fun test(key: Int) : Type3 {
    // ...
    return makeTest(key) // now this works
  }
  // ...
}
t
I can reproduce the issue in my real project with build198 and Kotlin 1.4.32 as well. So it looks like a Compose issue.
v
To reproduce this error in a newly created Compose project, just add the following code:
Copy code
abstract class AbstractB<Type>(d: Type) : AbstractA<Int, Type>(d) {
    override fun test(key: Int): Type {
        return super.test(key)
    }
}

abstract class AbstractA<Type1, Type2>(var d: Type2) {
    open fun test(key: Type1): Type2 = d
}
This code worked with Compose 0.4.0-build190 and Kotlin 1.4.32, but with Compose 0.4.0-build198 and Kotlin 1.4.32 we have compiler error
🎉 2
j
You both are amazing! Thanks for the repro. Looks like a bug in the upstream compiler that is only hit as part of the Compose code path. Debugging it now!
a
Any update on this? Facing the same issue.
j
Yeah, I already fixed it in master. You can use the latest binaries published by Jetbrains which already have the fix, or wait until the next Google release goes out for Android. I think the Google release may be delayed by an additional week more than normal due to some reasons around late landing changes.
a
The latest compose binaries using the
org.jetbrains.compose
dependency?
j
yeah, afaik that should work now
are you still seeing issues there?
t
I can confirm that the latest Jetbrains build fixes the issue. Thanks a lot!