andylamax
12/24/2023, 12:53 AMexpect interface Promise<out T>
• src/jvmMain/Promise.kt
@file:Suppress(
"ACTUAL_WITHOUT_EXPECT",
"ACTUAL_TYPE_ALIAS_TO_CLASS_WITH_DECLARATION_SITE_VARIANCE"
)
actual typealias Promise<T> = java.util.concurrent.CompletionStage<T>
Results are as follows
a) Without any suppresses, the compilation fails with
• 'actual typealias Promise<T> = CompletionStage<T>' has no corresponding expected declaration
• The following declaration is incompatible because declaration-site variances of type parameters are different
On both kotlin K1 (1.9.21) and K2 (2.0.0-Beta1,2.0.0-Beta2)
b) With @Suppress("ACTUAL_WITHOUT_EXPECT")
The program compiles file on K1 (1.9.21)
but fails on K2 (2.0.0-Beta1,2.0.0-Beta2)
• Expect declaration Promise
is incompatible with actual Promise
because declaration-site variances of type parameters are different
c) With @Suppress("ACTUAL_WITHOUT_EXPECT","ACTUAL_TYPE_ALIAS_TO_CLASS_WITH_DECLARATION_SITE_VARIANCE")
Results are similar to (b), its like the former suppress directive has no effect at all
Now I know the kotlin team doesn't really investigate code with suppresses, but how should we approach this currently?? I can't seem to be able to provide an actual type alias for this.
Also, is there a current issue for this?? Or should I file a ticket??Marc Reichelt
12/28/2023, 5:44 PMClassCastException
when run with 2.0.0-Beta2:
val Number.lightyears get() = Lightyears(this.toDouble())
val UInt.lightyears get() = Lightyears(this.toDouble())
data class Lightyears(val years: Double)
fun main() {
println(2.lightyears)
println(2U.lightyears)
}
Kotlin Playground: https://pl.kotl.in/0zkCeRL8P
This fails with:
Exception in thread "main" java.lang.ClassCastException: class kotlin.UInt cannot be cast to class java.lang.Number (kotlin.UInt is in unnamed module of loader 'app'; java.lang.Number is in module java.base of loader 'bootstrap')
Is this issue already known?Roman
01/01/2024, 11:28 AMCharlie Tapping
01/02/2024, 11:09 PMeygraber
01/03/2024, 3:40 AMRoman
01/09/2024, 10:21 AMjava: cannot access org.jetbrains.kotlin.fir.expressions.impl.FirElseIfTrueCondition
bad class file: /.../kotlin-compiler-2.0.0-Beta2.jar!/org/jetbrains/kotlin/fir/expressions/impl/FirElseIfTrueCondition.class
undeclared type variable: T
Please remove or make sure it appears in the correct subdirectory of the classpath.
Is there any other way I can check for "else" branch using K2 API?mitch
01/10/2024, 7:37 AMjava.lang.NullPointerException: Cannot invoke "kotlin.coroutines.Continuation.getContext()" because "$completion" is null
with the offending stack trace (which unfortunately I can't share) pointed to a simple currentCoroutineContext()
, to a generic code that have been running in production for quite some time without issues:
suspend fun <A> withObservability(fx: suspend ReactiveLogger.() -> A): A {
currentCoroutineContext() // blew up here
...
}
Also it's not deterministic: it doesn't happen to anywhere else in the codebase but one very specific endpoint. We've been using this function literally everywhere in the code and has been running rock solid for at least the last ~4 years. This is a bit over my head and I'm trying to understand how can I debug this.. why would the completion be null?
also maybe a red herring but we started seeing this after we upgraded Kotlin from 1.9.21 to 1.9.22
kotlinx.coroutines version 1.7.3
kotlin version 1.9.22
java 17.0.9
CI compilation passes, but potentially have generated a bad code.
After some investigation, with latest intellij somehow compilation failed with this error:
https://kotlinlang.slack.com/archives/C1CFAFJSK/p1704872052059009?thread_ts=1704719278.461759&cid=C1CFAFJSK
org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
File being compiled: /Users/myuwono/Development/path/to/File.kt
The root cause java.lang.AssertionError was thrown at: org.jetbrains.kotlin.backend.jvm.lower.AddContinuationLoweringKt.retargetToSuspendView(AddContinuationLowering.kt:500)
at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException(CodegenUtil.kt:253)
at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException$default(CodegenUtil.kt:237)
at org.jetbrains.kotlin.backend.common.phaser.PerformByIrFilePhase.invokeSequential(performByIrFile.kt:65)
at org.jetbrains.kotlin.backend.common.phaser.PerformByIrFilePhase.invoke(performByIrFile.kt:52)
at org.jetbrains.kotlin.backend.common.phaser.PerformByIrFilePhase.invoke(performByIrFile.kt:38)
at org.jetbrains.kotlin.backend.common.phaser.NamedCompilerPhase.phaseBody(CompilerPhase.kt:147)
at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedCompilerPhase.invoke(CompilerPhase.kt:94)
at org.jetbrains.kotlin.backend.common.phaser.CompositePhase.invoke(PhaseBuilders.kt:29)
at org.jetbrains.kotlin.backend.common.phaser.CompositePhase.invoke(PhaseBuilders.kt:16)
at org.jetbrains.kotlin.backend.common.phaser.NamedCompilerPhase.phaseBody(CompilerPhase.kt:147)
at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedCompilerPhase.invoke(CompilerPhase.kt:94)
at org.jetbrains.kotlin.backend.common.phaser.CompilerPhaseKt.invokeToplevel(CompilerPhase.kt:43)
at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.invokeLowerings(JvmIrCodegenFactory.kt:348)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.runLowerings(KotlinToJVMBytecodeCompiler.kt:330)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:114)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:43)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:165)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:50)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:104)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:48)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:463)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:62)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.doCompile(IncrementalCompilerRunner.kt:477)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:400)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.tryCompileIncrementally$lambda$6$compile(IncrementalCompilerRunner.kt:231)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.tryCompileIncrementally(IncrementalCompilerRunner.kt:247)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:116)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:657)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:105)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1624)
at jdk.internal.reflect.GeneratedMethodAccessor94.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
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:712)
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:399)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
and I didn't enable K2...juliocbcotta
01/23/2024, 11:22 PMkotlin version: 2.0.0-Beta3
error message: java.lang.NoClassDefFoundError: org/jetbrains/kotlin/ir/declarations/IrDeclarationOrigin$IR_BUILTINS_STUB
at androidx.compose.compiler.plugins.kotlin.analysis.StabilityInferencer.stabilityOf(Stability.kt:251)
at androidx.compose.compiler.plugins.kotlin.analysis.StabilityInferencer.stabilityOf(Stability.kt:360)
at androidx.compose.compiler.plugins.kotlin.analysis.StabilityInferencer.stabilityOf(Stability.kt:426)
Edoardo Luppi
01/25/2024, 12:07 PMpublic expect class CopyOnWriteArrayList<E>() : MutableList<E> {
public constructor(elements: Collection<E>)
... all the methods from MutableList. Not sure why but K2 requires overriding them explicitly
}
With an actual typealias per platform:
public actual typealias CopyOnWriteArrayList<E> = ArrayList<E> // Native
public actual typealias CopyOnWriteArrayList<E> = java.util.concurrent.CopyOnWriteArrayList<E> // JVM
public actual typealias CopyOnWriteArrayList<E> = ArrayList<E> // WASM WASI
public actual typealias CopyOnWriteArrayList<E> = ArrayList<E> // JS and WASM JS
K2 complains with this error:
e: file:///C:/Users/.../CopyOnWriteArrayList.kt:5:1 Expect declaration `CopyOnWriteArrayList` doesn't match actual `CopyOnWriteArrayList` because some expected members have no actual ones
But without telling me which expected members. Is this a bug?Ruslan Latypov
01/25/2024, 3:14 PMEdoardo Luppi
01/25/2024, 4:36 PMexpect class MyList<E> : List<E>
Will work fine in K1, but not in K2.
You'll be forced to override the interface methods.Federico Tomassetti
01/26/2024, 3:03 PMkubele
02/05/2024, 11:23 AMlifey
02/07/2024, 7:44 AMorg.opentest4j.AssertionFailedError: Unexpected exception thrown: java.lang.ClassCastException: class java.lang.Object cannot be cast to class kotlin.Unit (java.lang.Object is in module java.base of loader 'bootstrap'; kotlin.Unit is in unnamed module of loader 'app')
at app//org.junit.jupiter.api.AssertDoesNotThrow.createAssertionFailedError(AssertDoesNotThrow.java:83)
at app//org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:76)
at app//org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:59)
at app//org.junit.jupiter.api.Assertions.assertDoesNotThrow(Assertions.java:3195)
eygraber
02/07/2024, 5:39 PMPHondogo
02/13/2024, 2:33 PM@Composable invocations can only happen from the context of a @Composable function
.
It fails at those places where I use lambda for passing composables as paramaters. Now I need to explicitly write @Composable annotation on each such lambda.
For example: ListItem(supportingContent = @Composable {})
Previously I can write: ListItem(supportingContent = {})
Is it required for K2 now, or somehow can be set to compile without such restrictions?Matt Groth
02/13/2024, 4:57 PMmust override 'spliterator' because it inherits multiple interface methods for it.
Already reported (must override ‘spliterator’ because it inherits multiple interface methods for it.)
Note the offending class is in a common source set in a module with JS and Jvm targets, so the Spliterator class is not resolvable.
I came here to check if anyone knows a quick workaround, so I can manage to upgrade anyway. Because otherwise I might have to wait for Beta5.s3rius
02/18/2024, 11:21 AMclass FunInterfaceTest {
fun interface FunInterface {
suspend operator fun invoke() // <- suspend
}
fun func(f: FunInterface) = Unit
@Test
fun `this fails on k2`() {
val lambda: () -> Unit = { } // <- no suspend
func(f = lambda)
}
@Test
fun `this always works`() {
val lambda: suspend () -> Unit = { } // <- suspend
func(f = lambda)
}
}
With this first test throwing the following runtime error:
java.lang.ClassCastException: class <class>$lambda$1 cannot be cast to class kotlin.jvm.functions.Function1 (<class>$lambda$1 and kotlin.jvm.functions.Function1 are in unnamed module of loader 'app')
In short: I'm calling a function f
that expects a FunInterface
. The fun interface's function is suspending.
On 1.9.22, I can use a lambda of type () -> Unit
or of type suspend () -> Unit
to call f
.
On K2 beta 4, I can only use a lambda of type suspend () -> Unit
to call f
.
I have a sneaking suspicion that using the non-suspend variant on 1.9.22 worked just by coincidence, and that I've been doing something that isn't actually allowed by the language.
Still, it's a change of behavior compared to 1.9. And I would have assumed that the compile-time type checking should throw an error during compilation if this were disallowed. Is this worth reporting?Aftab Ahmad
02/26/2024, 4:23 PMkotlinx-serialization
is failing when the K2 kapt flag (kapt.use.k2=true)
is enabled:
> Task :app:kaptGenerateStubsDebugKotlin
w: K2 kapt is an experimental feature. Use with caution.
> Task :app:kaptDebugKotlin FAILED
serialization/app/build/tmp/kapt3/stubs/debug/com/sample/serialization/response/SampleResponse.java:94: error: illegal '.'
public static final com.sample.serialization.response.SampleResponse..serializer INSTANCE = null;
I filed a ticket on the kotlinx-serialization repo but not sure if that was the best place as the issue surfaces there but the bug might is in K2 kaptNick
02/27/2024, 3:43 PMpublic interface Pool<in T> {
public operator fun plusAssign (item: T)
public operator fun minusAssign(item: T)
}
public expect open class SetPool<T> private constructor(delegate: MutableSet<T>): Pool<T>, Set<T> {
public constructor()
}
And the corresponding actual:
public actual open class SetPool<T> actual constructor(private val delegate: MutableSet<T>): Pool<T>, Set<T> by delegate {
public actual constructor(): this(CopyOnWriteArraySet())
override fun plusAssign (item: T) { delegate += item }
override fun minusAssign(item: T) { delegate -= item }
}
This worked in 1.9.x, but now fails with the following error:
'actual class SetPool<T> : Pool<T>, Set<T>' has no corresponding members for expected class members:
expect fun contains(element: T): Boolean
The following declaration is incompatible because modality is different:
fun contains(element: T): Boolean
expect fun containsAll(elements: Collection<T>): Boolean
The following declaration is incompatible because modality is different:
fun containsAll(elements: Collection<T>): Boolean
expect fun isEmpty(): Boolean
The following declaration is incompatible because modality is different:
fun isEmpty(): Boolean
expect fun iterator(): Iterator<T>
The following declaration is incompatible because modality is different:
fun iterator(): Iterator<T>
expect val size: Int
The following declaration is incompatible because modality is different:
val size: Int
is there some issue with expect
/`actual` classes implementing interfaces?dniHze
02/27/2024, 4:36 PMe: org.jetbrains.kotlin.util.FileAnalysisException: While analysing /Users/a.dorosh/StudioProjects/*******/MviBaseDsl.kt:58:21: java.lang.IllegalArgumentException: Failed requirement.
at org.jetbrains.kotlin.util.AnalysisExceptionsKt.wrapIntoFileAnalysisExceptionIfNeeded(AnalysisExceptions.kt:56)
at org.jetbrains.kotlin.fir.FirCliExceptionHandler.handleExceptionOnFileAnalysis(Utils.kt:180)
at org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirDeclarationsResolveTransformer.transformFile(FirDeclarationsResolveTransformer.kt:1575)
at org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformerDispatcher.transformFile(FirAbstractBodyResolveTransformerDispatcher.kt:57)
at org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformerDispatcher.transformFile(FirAbstractBodyResolveTransformerDispatcher.kt:24)
at org.jetbrains.kotlin.fir.declarations.FirFile.transform(FirFile.kt:48)
***
Robert Jaros
03/01/2024, 3:20 PM2.0.0-Beta4
and my build log is full of warnings: This code uses error suppression for 'EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE'. While it might compile and work, the compiler behavior is UNSPECIFIED and WON'T BE PRESERVED. Please report your use case to the Kotlin issue tracker instead: <https://kotl.in/issue>
. Is there any way to suppress these suppression warnings?Robert Jaros
03/01/2024, 3:46 PM> Task :kilua:compileTestDevelopmentExecutableKotlinJs
w: KLIB resolver: The same 'unique_name=dev.kilua:kilua' found in more than one library: /home/rjaros/git/kilua/kilua/build/classes/kotlin/js/main, /home/rjaros/git/kilua/kilua/build/libs/kilua-js-0.0.1.klib
> Task :kilua:compileTestDevelopmentExecutableKotlinWasmJs
w: KLIB resolver: The same 'unique_name=dev.kilua:kilua' found in more than one library: /home/rjaros/git/kilua/kilua/build/classes/kotlin/wasmJs/main, /home/rjaros/git/kilua/kilua/build/libs/kilua-wasm-js-0.0.1.klib
Robert Jaros
03/05/2024, 6:56 PMRobert Jaros
03/06/2024, 7:05 AMZac Sweers
03/09/2024, 4:59 AMKtSourceModule.moduleName
reports the source set name now whereas ModuleDescriptor.name
in K1 reported the project name. Considering this name participates in name mangling, is this expected behavior?Nick
03/11/2024, 5:25 AM> Task :controls:wasmJsJar
kotlinx.coroutines.JobCancellationException: Parent job is Cancelling; job=ScopeCoroutine{Cancelling}@7415da4b
Caused by: kotlin.io.NoSuchFileException: /###/doodle/Core/doodle_repo_image_shorter.png: The source file doesn't exist.
at kotlin.io.FilesKt__UtilsKt.copyRecursively(Utils.kt:294)
at kotlin.io.FilesKt__UtilsKt.copyRecursively$default(Utils.kt:288)
at org.jetbrains.dokka.base.renderers.FileWriter$copyFromDirectory$2.invokeSuspend(FileWriter.kt:56)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
kotlinx.coroutines.JobCancellationException: Parent job is Cancelling; job=ScopeCoroutine{Cancelling}@7415da4b
Caused by: kotlin.io.NoSuchFileException: /###/doodle/Core/doodle_repo_image_shorter.png: The source file doesn't exist.
at kotlin.io.FilesKt__UtilsKt.copyRecursively(Utils.kt:294)
Failed to write org.jetbrains.dokka.base.renderers.FileWriter@47422d22. Parent job is Cancelling
Failed to write org.jetbrains.dokka.base.renderers.FileWriter@47422d22. Parent job is Cancelling
Nick
03/11/2024, 5:32 AMWebAssembly.instantiateStreaming(): Compiling function #17996:"io.nacular.doodle.layout.constraints.impl.Const..." failed: call[1] expected type (ref null 3131), found local.get of type (ref null 348) @+1486748
CompileError: WebAssembly.instantiateStreaming(): Compiling function #17996:"io.nacular.doodle.layout.constraints.impl.Const..." failed: call[1] expected type (ref null 3131), found local.get of type (ref null 348) @+1486748
i've narrowed it down to a trivial case:
simple app within src/wasmJsMain
import io.nacular.doodle.application.Application
import io.nacular.doodle.application.application
import io.nacular.doodle.core.Display
import io.nacular.doodle.core.view
import io.nacular.doodle.drawing.Color.Companion.Red
import io.nacular.doodle.drawing.paint
import io.nacular.doodle.geometry.Size
import io.nacular.doodle.layout.constraints.constrain
import io.nacular.doodle.layout.constraints.fill
import org.kodein.di.instance
class TestApp(display: Display): Application {
init {
display += view {
size = Size(100)
render = {
rect(bounds.atOrigin, fill = Red.paint)
}
}
display.layout = constrain(display.first(), fill) // this line pulls in the class that fails to compile
}
override fun shutdown() {
// no-op
}
}
fun main() {
application {
TestApp(instance())
}
}
build.gradle.kts
@file:OptIn(ExperimentalWasmDsl::class)
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
group = "org.example"
version = "1.0-SNAPSHOT"
plugins {
kotlin("multiplatform") version "2.0.0-Beta4"
}
repositories {
mavenCentral()
maven ("<https://oss.sonatype.org/content/repositories/snapshots>") // snapshots
mavenLocal ()
}
kotlin {
wasmJs {
compilations.all {
kotlinOptions {
moduleKind = "umd"
sourceMapEmbedSources = "always"
}
}
browser {
testTask { enabled = false }
}
binaries.executable()
}
sourceSets {
val doodleVersion = "0.11.0-SNAPSHOT"
commonMain.dependencies {
implementation("io.nacular.doodle:core:$doodleVersion")
}
val wasmJsMain by getting {
dependencies {
implementation("io.nacular.doodle:browser:$doodleVersion")
}
}
}
}
Ola Adolfsson
03/12/2024, 8:45 AMZac Sweers
03/12/2024, 10:09 PM