From b1711eb0df892e8396a74c17f23e98481958ad60 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Tue, 11 Feb 2025 11:15:13 +0100 Subject: [PATCH] Restore allWarningsAsErrors in main source-sets (#4336) --- .../kotlin/configure-compilation-conventions.gradle.kts | 4 ++-- gradle.properties | 1 - kotlinx-coroutines-core/common/src/Builders.common.kt | 4 +--- kotlinx-coroutines-core/common/src/CoroutineScope.kt | 2 +- kotlinx-coroutines-core/common/src/Supervisor.kt | 3 +-- kotlinx-coroutines-core/common/src/Timeout.kt | 2 +- kotlinx-coroutines-core/common/src/channels/Channel.kt | 2 -- kotlinx-coroutines-core/common/src/flow/Migration.kt | 2 +- .../common/src/internal/LockFreeLinkedList.common.kt | 2 -- .../common/src/internal/Synchronized.common.kt | 3 ++- kotlinx-coroutines-core/jvm/src/Builders.kt | 1 + kotlinx-coroutines-core/jvm/src/channels/Actor.kt | 1 + kotlinx-coroutines-core/native/src/Builders.kt | 3 ++- .../jvm/src/migration/TestCoroutineDispatcher.kt | 8 ++++---- kotlinx-coroutines-test/wasmJs/src/TestBuilders.kt | 1 + .../api/kotlinx-coroutines-reactive.api | 2 +- reactive/kotlinx-coroutines-reactive/src/Publish.kt | 1 + reactive/kotlinx-coroutines-reactive/src/ReactiveFlow.kt | 1 + 18 files changed, 21 insertions(+), 22 deletions(-) diff --git a/buildSrc/src/main/kotlin/configure-compilation-conventions.gradle.kts b/buildSrc/src/main/kotlin/configure-compilation-conventions.gradle.kts index dfbcd85590..27f3737021 100644 --- a/buildSrc/src/main/kotlin/configure-compilation-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/configure-compilation-conventions.gradle.kts @@ -16,9 +16,9 @@ configure(subprojects) { apiVersion = it versionsAreNotOverridden = false } - if (isMainTaskName && versionsAreNotOverridden && !unpublished.contains(project.name)) { + if (isMainTaskName && !unpublished.contains(project.name)) { allWarningsAsErrors = true - freeCompilerArgs.add("-Xexplicit-api=strict") + freeCompilerArgs.addAll("-Xexplicit-api=strict", "-Xdont-warn-on-error-suppression") } /* Coroutines do not interop with Java and these flags provide a significant * (i.e. close to double-digit) reduction in both bytecode and optimized dex size */ diff --git a/gradle.properties b/gradle.properties index c0eb2f3ddc..67b17c995b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,6 @@ version=1.10.1-SNAPSHOT group=org.jetbrains.kotlinx kotlin_version=2.1.0 -kotlin_language_version=2.1 # DO NOT rename this property without adapting kotlinx.train build chain: atomicfu_version=0.26.1 diff --git a/kotlinx-coroutines-core/common/src/Builders.common.kt b/kotlinx-coroutines-core/common/src/Builders.common.kt index bf8a989188..23ef7665b5 100644 --- a/kotlinx-coroutines-core/common/src/Builders.common.kt +++ b/kotlinx-coroutines-core/common/src/Builders.common.kt @@ -1,6 +1,7 @@ @file:JvmMultifileClass @file:JvmName("BuildersKt") @file:OptIn(ExperimentalContracts::class) +@file:Suppress("LEAKED_IN_PLACE_LAMBDA", "WRONG_INVOCATION_KIND") package kotlinx.coroutines @@ -153,7 +154,6 @@ public suspend fun withContext( // FAST PATH #1 -- new context is the same as the old one if (newContext === oldContext) { val coroutine = ScopeCoroutine(newContext, uCont) - @Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws return@sc coroutine.startUndispatchedOrReturn(coroutine, block) } // FAST PATH #2 -- the new dispatcher is the same as the old one (something else changed) @@ -162,13 +162,11 @@ public suspend fun withContext( val coroutine = UndispatchedCoroutine(newContext, uCont) // There are changes in the context, so this thread needs to be updated withCoroutineContext(coroutine.context, null) { - @Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws return@sc coroutine.startUndispatchedOrReturn(coroutine, block) } } // SLOW PATH -- use new dispatcher val coroutine = DispatchedCoroutine(newContext, uCont) - @Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws block.startCoroutineCancellable(coroutine, coroutine) coroutine.getResult() } diff --git a/kotlinx-coroutines-core/common/src/CoroutineScope.kt b/kotlinx-coroutines-core/common/src/CoroutineScope.kt index 973429ca06..6dc52b3474 100644 --- a/kotlinx-coroutines-core/common/src/CoroutineScope.kt +++ b/kotlinx-coroutines-core/common/src/CoroutineScope.kt @@ -1,4 +1,5 @@ @file:OptIn(ExperimentalContracts::class) +@file:Suppress("LEAKED_IN_PLACE_LAMBDA", "WRONG_INVOCATION_KIND") package kotlinx.coroutines @@ -281,7 +282,6 @@ public suspend fun coroutineScope(block: suspend CoroutineScope.() -> R): R } return suspendCoroutineUninterceptedOrReturn { uCont -> val coroutine = ScopeCoroutine(uCont.context, uCont) - @Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws coroutine.startUndispatchedOrReturn(coroutine, block) } } diff --git a/kotlinx-coroutines-core/common/src/Supervisor.kt b/kotlinx-coroutines-core/common/src/Supervisor.kt index c1d2145680..900436e6f5 100644 --- a/kotlinx-coroutines-core/common/src/Supervisor.kt +++ b/kotlinx-coroutines-core/common/src/Supervisor.kt @@ -1,5 +1,5 @@ @file:OptIn(ExperimentalContracts::class) -@file:Suppress("DEPRECATION_ERROR") +@file:Suppress("LEAKED_IN_PLACE_LAMBDA", "WRONG_INVOCATION_KIND") package kotlinx.coroutines @@ -53,7 +53,6 @@ public suspend fun supervisorScope(block: suspend CoroutineScope.() -> R): R } return suspendCoroutineUninterceptedOrReturn { uCont -> val coroutine = SupervisorCoroutine(uCont.context, uCont) - @Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws coroutine.startUndispatchedOrReturn(coroutine, block) } } diff --git a/kotlinx-coroutines-core/common/src/Timeout.kt b/kotlinx-coroutines-core/common/src/Timeout.kt index d2fcca5521..65e68ba299 100644 --- a/kotlinx-coroutines-core/common/src/Timeout.kt +++ b/kotlinx-coroutines-core/common/src/Timeout.kt @@ -1,4 +1,5 @@ @file:OptIn(ExperimentalContracts::class) +@file:Suppress("LEAKED_IN_PLACE_LAMBDA", "WRONG_INVOCATION_KIND") package kotlinx.coroutines @@ -40,7 +41,6 @@ public suspend fun withTimeout(timeMillis: Long, block: suspend CoroutineSco } if (timeMillis <= 0L) throw TimeoutCancellationException("Timed out immediately") return suspendCoroutineUninterceptedOrReturn { uCont -> - @Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws setupTimeout(TimeoutCoroutine(timeMillis, uCont), block) } } diff --git a/kotlinx-coroutines-core/common/src/channels/Channel.kt b/kotlinx-coroutines-core/common/src/channels/Channel.kt index b4b80fb789..3e3c0f5fae 100644 --- a/kotlinx-coroutines-core/common/src/channels/Channel.kt +++ b/kotlinx-coroutines-core/common/src/channels/Channel.kt @@ -1,5 +1,3 @@ -@file:Suppress("FunctionName") - package kotlinx.coroutines.channels import kotlinx.coroutines.* diff --git a/kotlinx-coroutines-core/common/src/flow/Migration.kt b/kotlinx-coroutines-core/common/src/flow/Migration.kt index 45b8abc671..090f6f409b 100644 --- a/kotlinx-coroutines-core/common/src/flow/Migration.kt +++ b/kotlinx-coroutines-core/common/src/flow/Migration.kt @@ -1,6 +1,6 @@ @file:JvmMultifileClass @file:JvmName("FlowKt") -@file:Suppress("unused", "DeprecatedCallableAddReplaceWith", "UNUSED_PARAMETER", "NO_EXPLICIT_RETURN_TYPE_IN_API_MODE") +@file:Suppress("unused", "DeprecatedCallableAddReplaceWith", "UNUSED_PARAMETER") package kotlinx.coroutines.flow diff --git a/kotlinx-coroutines-core/common/src/internal/LockFreeLinkedList.common.kt b/kotlinx-coroutines-core/common/src/internal/LockFreeLinkedList.common.kt index 32209fc0ac..b925089b0c 100644 --- a/kotlinx-coroutines-core/common/src/internal/LockFreeLinkedList.common.kt +++ b/kotlinx-coroutines-core/common/src/internal/LockFreeLinkedList.common.kt @@ -1,5 +1,3 @@ -@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE") - package kotlinx.coroutines.internal /** @suppress **This is unstable API and it is subject to change.** */ diff --git a/kotlinx-coroutines-core/common/src/internal/Synchronized.common.kt b/kotlinx-coroutines-core/common/src/internal/Synchronized.common.kt index b92c51502a..43777f20db 100644 --- a/kotlinx-coroutines-core/common/src/internal/Synchronized.common.kt +++ b/kotlinx-coroutines-core/common/src/internal/Synchronized.common.kt @@ -1,3 +1,5 @@ +@file:Suppress("LEAKED_IN_PLACE_LAMBDA", "WRONG_INVOCATION_KIND") + package kotlinx.coroutines.internal import kotlinx.coroutines.* @@ -24,6 +26,5 @@ public inline fun synchronized(lock: SynchronizedObject, block: () -> T): T contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - @Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws return synchronizedImpl(lock, block) } diff --git a/kotlinx-coroutines-core/jvm/src/Builders.kt b/kotlinx-coroutines-core/jvm/src/Builders.kt index d2249bfdd0..3fed0ad9cb 100644 --- a/kotlinx-coroutines-core/jvm/src/Builders.kt +++ b/kotlinx-coroutines-core/jvm/src/Builders.kt @@ -1,6 +1,7 @@ @file:JvmMultifileClass @file:JvmName("BuildersKt") @file:OptIn(ExperimentalContracts::class) +@file:Suppress("LEAKED_IN_PLACE_LAMBDA", "WRONG_INVOCATION_KIND") package kotlinx.coroutines diff --git a/kotlinx-coroutines-core/jvm/src/channels/Actor.kt b/kotlinx-coroutines-core/jvm/src/channels/Actor.kt index ef74a08f35..68ba76e47e 100644 --- a/kotlinx-coroutines-core/jvm/src/channels/Actor.kt +++ b/kotlinx-coroutines-core/jvm/src/channels/Actor.kt @@ -119,6 +119,7 @@ public fun CoroutineScope.actor( return coroutine } +@Suppress("MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE_DEPRECATION_WARNING") private open class ActorCoroutine( parentContext: CoroutineContext, channel: Channel, diff --git a/kotlinx-coroutines-core/native/src/Builders.kt b/kotlinx-coroutines-core/native/src/Builders.kt index 77b7cacebb..4f94f19b53 100644 --- a/kotlinx-coroutines-core/native/src/Builders.kt +++ b/kotlinx-coroutines-core/native/src/Builders.kt @@ -1,4 +1,6 @@ @file:OptIn(ExperimentalContracts::class, ObsoleteWorkersApi::class) +@file:Suppress("LEAKED_IN_PLACE_LAMBDA", "WRONG_INVOCATION_KIND") + package kotlinx.coroutines import kotlinx.cinterop.* @@ -64,7 +66,6 @@ public actual fun runBlocking(context: CoroutineContext, block: suspend Coro var completed = false ThreadLocalKeepAlive.addCheck { !completed } try { - @Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws coroutine.start(CoroutineStart.DEFAULT, coroutine, block) return coroutine.joinBlocking() } finally { diff --git a/kotlinx-coroutines-test/jvm/src/migration/TestCoroutineDispatcher.kt b/kotlinx-coroutines-test/jvm/src/migration/TestCoroutineDispatcher.kt index 7f8062257d..585f77b7b9 100644 --- a/kotlinx-coroutines-test/jvm/src/migration/TestCoroutineDispatcher.kt +++ b/kotlinx-coroutines-test/jvm/src/migration/TestCoroutineDispatcher.kt @@ -45,18 +45,18 @@ public class TestCoroutineDispatcher(public override val scheduler: TestCoroutin private fun post(block: Runnable, context: CoroutineContext) = scheduler.registerEvent(this, 0, block, context) { false } - val currentTime: Long + public val currentTime: Long get() = scheduler.currentTime - fun advanceUntilIdle(): Long { + public fun advanceUntilIdle(): Long { val oldTime = scheduler.currentTime scheduler.advanceUntilIdle() return scheduler.currentTime - oldTime } - fun runCurrent(): Unit = scheduler.runCurrent() + public fun runCurrent(): Unit = scheduler.runCurrent() - fun cleanupTestCoroutines() { + public fun cleanupTestCoroutines() { // process any pending cancellations or completions, but don't advance time scheduler.runCurrent() if (!scheduler.isIdle(strict = false)) { diff --git a/kotlinx-coroutines-test/wasmJs/src/TestBuilders.kt b/kotlinx-coroutines-test/wasmJs/src/TestBuilders.kt index ed9f9c9139..8409b0f2d0 100644 --- a/kotlinx-coroutines-test/wasmJs/src/TestBuilders.kt +++ b/kotlinx-coroutines-test/wasmJs/src/TestBuilders.kt @@ -6,6 +6,7 @@ import kotlin.js.* public actual typealias TestResult = JsPromiseInterfaceForTesting +@Suppress("INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION") internal actual fun createTestResult(testProcedure: suspend CoroutineScope.() -> Unit): TestResult = GlobalScope.promise { testProcedure() diff --git a/reactive/kotlinx-coroutines-reactive/api/kotlinx-coroutines-reactive.api b/reactive/kotlinx-coroutines-reactive/api/kotlinx-coroutines-reactive.api index 3a2ea12d7a..7436696aed 100644 --- a/reactive/kotlinx-coroutines-reactive/api/kotlinx-coroutines-reactive.api +++ b/reactive/kotlinx-coroutines-reactive/api/kotlinx-coroutines-reactive.api @@ -37,7 +37,7 @@ public final class kotlinx/coroutines/reactive/FlowSubscription : kotlinx/corout public final field flow Lkotlinx/coroutines/flow/Flow; public final field subscriber Lorg/reactivestreams/Subscriber; public fun (Lkotlinx/coroutines/flow/Flow;Lorg/reactivestreams/Subscriber;Lkotlin/coroutines/CoroutineContext;)V - public fun cancel ()V + public synthetic fun cancel ()V public fun request (J)V } diff --git a/reactive/kotlinx-coroutines-reactive/src/Publish.kt b/reactive/kotlinx-coroutines-reactive/src/Publish.kt index a58e01f5d7..cb3e596268 100644 --- a/reactive/kotlinx-coroutines-reactive/src/Publish.kt +++ b/reactive/kotlinx-coroutines-reactive/src/Publish.kt @@ -316,6 +316,7 @@ public class PublisherCoroutine( signalCompleted(cause, handled) } + @Suppress("OVERRIDE_DEPRECATION") // Remove after 2.2.0 override fun cancel() { // Specification requires that after cancellation publisher stops signalling // This flag distinguishes subscription cancellation request from the job crash diff --git a/reactive/kotlinx-coroutines-reactive/src/ReactiveFlow.kt b/reactive/kotlinx-coroutines-reactive/src/ReactiveFlow.kt index 79cc87aa1d..e1dcf0f63e 100644 --- a/reactive/kotlinx-coroutines-reactive/src/ReactiveFlow.kt +++ b/reactive/kotlinx-coroutines-reactive/src/ReactiveFlow.kt @@ -244,6 +244,7 @@ public class FlowSubscription( } } + @Deprecated("Since 1.2.0, binary compatibility with versions <= 1.1.x", level = DeprecationLevel.HIDDEN) override fun cancel() { cancellationRequested = true cancel(null)