自从 Kotlin 2.0.0-RC1 最近发布以来,我决定为 2.0 升级准备代码库,但在使用“上下文接收器”的地方遇到了意外的编译问题。
考虑以下使用“上下文接收器”功能的简单代码:
interface User
object UserNotFound
context(Raise<UserNotFound>)
fun findUser(): User = raise(UserNotFound)
fun main() {
either {
findUser()
}.onLeft {
println("Uh-oh, $it")
}
}
上下文接收器应该显式启用,所以我的构建配置是:
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
}
}
一旦我从 Kotlin
2.0.0-Beta2
升级到 2.0.0-Beta3
,构建就会失败并出现以下错误:
e: .../src/main/kotlin/org/example/Library.kt:13:5 没有足够的信息来推断“Error”的类型参数。
我可以在配置中调整什么来修复编译或者 Kotlin 或 Arrow 方面的一些兼容性问题吗?
这是一个 KT-67699 错误。应该在 2.0.0-RC3 中修复。