Search code examples
kotlinarrow-kt

Not enough information to infer type argument for 'Error' using Raise context receiver since Kotlin 2.0.0-Beta3


Since Kotlin 2.0.0-RC1 was recently released, I decided to prepare my codebase for the 2.0 upgrade and faced unexpected compilation issue in places where "context receivers" was used.

Consider the following simple code using "context receivers" feature:

interface User
object UserNotFound

context(Raise<UserNotFound>)
fun findUser(): User = raise(UserNotFound)

fun main() {
    either {
        findUser()
    }.onLeft {
        println("Uh-oh, $it")
    }
}

Context receivers should be explicitly enabled, so my build configuration is:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "2.0.0-Beta2"
}

repositories {
    mavenCentral()
}

dependencies {
    implementation(platform("io.arrow-kt:arrow-stack:1.2.4"))
    implementation("io.arrow-kt:arrow-core")
}

tasks.withType<KotlinCompile>().configureEach {
    compilerOptions {
        freeCompilerArgs.add("-Xcontext-receivers") // <--- enabling context receivers explicitly
    }
}

As soon as I upgrade from Kotlin 2.0.0-Beta2 to 2.0.0-Beta3, build fails with the following error:

e: .../src/main/kotlin/org/example/Library.kt:13:5 Not enough information to infer type argument for 'Error'.

Is there anything I can adjust in my configuration to fix compilation or it's some compatibility issue on Kotlin or Arrow side?


Solution

  • That was a KT-67699 bug. Should be fixed in 2.0.0-RC3.