Skip to content

Commit 9cbad7d

Browse files
authored
Enable strict explicit mode (#1877)
1 parent 5b610bb commit 9cbad7d

File tree

65 files changed

+146
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+146
-125
lines changed

benchmarks/src/main/kotlin/benchmarks/common/BenchmarkUtils.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package benchmarks.common
66

77
import java.util.concurrent.*
88

9-
fun doGeomDistrWork(work: Int) {
9+
public fun doGeomDistrWork(work: Int) {
1010
// We use geometric distribution here. We also checked on macbook pro 13" (2017) that the resulting work times
1111
// are distributed geometrically, see https://github.com/Kotlin/kotlinx.coroutines/pull/1464#discussion_r355705325
1212
val p = 1.0 / work

gradle/compile-common.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ kotlin.sourceSets {
1212
api "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
1313
}
1414
}
15+
16+
17+
kotlin.sourceSets.matching({ it.name.contains("Main") }).all { srcSet ->
18+
project.ext.set("kotlin.mpp.freeCompilerArgsForSourceSet.${srcSet.name}", "-Xexplicit-api=strict")
19+
}

gradle/compile-jvm.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ repositories {
2323
maven { url "https://dl.bintray.com/devexperts/Maven/" }
2424
}
2525

26+
compileKotlin {
27+
kotlinOptions {
28+
freeCompilerArgs += ['-Xexplicit-api=strict']
29+
}
30+
}
31+
2632
tasks.withType(Test) {
2733
testLogging {
2834
showStandardStreams = true

integration/kotlinx-coroutines-jdk8/src/time/Time.kt

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,24 @@ import java.time.temporal.*
1212
/**
1313
* "java.time" adapter method for [kotlinx.coroutines.delay].
1414
*/
15-
public suspend fun delay(duration: Duration) =
16-
kotlinx.coroutines.delay(duration.coerceToMillis())
15+
public suspend fun delay(duration: Duration): Unit = delay(duration.coerceToMillis())
1716

1817
/**
1918
* "java.time" adapter method for [kotlinx.coroutines.flow.debounce].
2019
*/
2120
@FlowPreview
22-
public fun <T> Flow<T>.debounce(timeout: Duration) = debounce(timeout.coerceToMillis())
21+
public fun <T> Flow<T>.debounce(timeout: Duration): Flow<T> = debounce(timeout.coerceToMillis())
2322

2423
/**
2524
* "java.time" adapter method for [kotlinx.coroutines.flow.sample].
2625
*/
2726
@FlowPreview
28-
public fun <T> Flow<T>.sample(period: Duration) = sample(period.coerceToMillis())
27+
public fun <T> Flow<T>.sample(period: Duration): Flow<T> = sample(period.coerceToMillis())
2928

3029
/**
3130
* "java.time" adapter method for [SelectBuilder.onTimeout].
3231
*/
33-
public fun <R> SelectBuilder<R>.onTimeout(duration: Duration, block: suspend () -> R) =
32+
public fun <R> SelectBuilder<R>.onTimeout(duration: Duration, block: suspend () -> R): Unit =
3433
onTimeout(duration.coerceToMillis(), block)
3534

3635
/**

integration/kotlinx-coroutines-slf4j/src/MDCContext.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class MDCContext(
4848
/**
4949
* Key of [MDCContext] in [CoroutineContext].
5050
*/
51-
companion object Key : CoroutineContext.Key<MDCContext>
51+
public companion object Key : CoroutineContext.Key<MDCContext>
5252

5353
/** @suppress */
5454
override fun updateThreadContext(context: CoroutineContext): MDCContextMap {

js/js-stub/src/Performance.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
package org.w3c.performance
66

77
public abstract class Performance {
8-
abstract fun now(): Double
8+
public abstract fun now(): Double
99
}

kotlinx-coroutines-core/common/src/AbstractCoroutine.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public abstract class AbstractCoroutine<in T>(
113113
afterResume(state)
114114
}
115115

116-
protected open fun afterResume(state: Any?) = afterCompletion(state)
116+
protected open fun afterResume(state: Any?): Unit = afterCompletion(state)
117117

118118
internal final override fun handleOnCompletionException(exception: Throwable) {
119119
handleCoroutineException(context, exception)

kotlinx-coroutines-core/common/src/CancellableContinuation.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ internal fun CancellableContinuation<*>.removeOnCancellation(node: LockFreeLinke
288288
* @suppress **This an internal API and should not be used from general code.**
289289
*/
290290
@InternalCoroutinesApi
291-
public fun CancellableContinuation<*>.disposeOnCancellation(handle: DisposableHandle) =
291+
public fun CancellableContinuation<*>.disposeOnCancellation(handle: DisposableHandle): Unit =
292292
invokeOnCancellation(handler = DisposeOnCancel(handle).asHandler)
293293

294294
// --------------- implementation details ---------------

kotlinx-coroutines-core/common/src/CompletableDeferred.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public interface CompletableDeferred<T> : Deferred<T> {
5555
* [CompletableDeferred.completeExceptionally].
5656
*/
5757
@ExperimentalCoroutinesApi // since 1.3.2, tentatively until 1.4.0
58-
public fun <T> CompletableDeferred<T>.completeWith(result: Result<T>) = result.fold({ complete(it) }, { completeExceptionally(it) })
58+
public fun <T> CompletableDeferred<T>.completeWith(result: Result<T>): Boolean =
59+
result.fold({ complete(it) }, { completeExceptionally(it) })
5960

6061
/**
6162
* Creates a [CompletableDeferred] in an _active_ state.

kotlinx-coroutines-core/common/src/CoroutineDispatcher.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public abstract class CoroutineDispatcher :
8787
* @suppress **This an internal API and should not be used from general code.**
8888
*/
8989
@InternalCoroutinesApi
90-
public open fun dispatchYield(context: CoroutineContext, block: Runnable) = dispatch(context, block)
90+
public open fun dispatchYield(context: CoroutineContext, block: Runnable): Unit = dispatch(context, block)
9191

9292
/**
9393
* Returns a continuation that wraps the provided [continuation], thus intercepting all resumptions.
@@ -115,7 +115,7 @@ public abstract class CoroutineDispatcher :
115115
"The dispatcher to the right of `+` just replaces the dispatcher to the left.",
116116
level = DeprecationLevel.ERROR
117117
)
118-
public operator fun plus(other: CoroutineDispatcher) = other
118+
public operator fun plus(other: CoroutineDispatcher): CoroutineDispatcher = other
119119

120120
/** @suppress for nicer debugging */
121121
override fun toString(): String = "$classSimpleName@$hexAddress"

kotlinx-coroutines-core/common/src/CoroutineStart.kt

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
4-
4+
@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE")
55
package kotlinx.coroutines
66

77
import kotlinx.coroutines.CoroutineStart.*
@@ -85,12 +85,12 @@ public enum class CoroutineStart {
8585
* @suppress **This an internal API and should not be used from general code.**
8686
*/
8787
@InternalCoroutinesApi
88-
public operator fun <T> invoke(block: suspend () -> T, completion: Continuation<T>) =
88+
public operator fun <T> invoke(block: suspend () -> T, completion: Continuation<T>): Unit =
8989
when (this) {
90-
CoroutineStart.DEFAULT -> block.startCoroutineCancellable(completion)
91-
CoroutineStart.ATOMIC -> block.startCoroutine(completion)
92-
CoroutineStart.UNDISPATCHED -> block.startCoroutineUndispatched(completion)
93-
CoroutineStart.LAZY -> Unit // will start lazily
90+
DEFAULT -> block.startCoroutineCancellable(completion)
91+
ATOMIC -> block.startCoroutine(completion)
92+
UNDISPATCHED -> block.startCoroutineUndispatched(completion)
93+
LAZY -> Unit // will start lazily
9494
}
9595

9696
/**
@@ -104,12 +104,12 @@ public enum class CoroutineStart {
104104
* @suppress **This an internal API and should not be used from general code.**
105105
*/
106106
@InternalCoroutinesApi
107-
public operator fun <R, T> invoke(block: suspend R.() -> T, receiver: R, completion: Continuation<T>) =
107+
public operator fun <R, T> invoke(block: suspend R.() -> T, receiver: R, completion: Continuation<T>): Unit =
108108
when (this) {
109-
CoroutineStart.DEFAULT -> block.startCoroutineCancellable(receiver, completion)
110-
CoroutineStart.ATOMIC -> block.startCoroutine(receiver, completion)
111-
CoroutineStart.UNDISPATCHED -> block.startCoroutineUndispatched(receiver, completion)
112-
CoroutineStart.LAZY -> Unit // will start lazily
109+
DEFAULT -> block.startCoroutineCancellable(receiver, completion)
110+
ATOMIC -> block.startCoroutine(receiver, completion)
111+
UNDISPATCHED -> block.startCoroutineUndispatched(receiver, completion)
112+
LAZY -> Unit // will start lazily
113113
}
114114

115115
/**

kotlinx-coroutines-core/common/src/Delay.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface Delay {
2525
* If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
2626
* immediately resumes with [CancellationException].
2727
*/
28-
suspend fun delay(time: Long) {
28+
public suspend fun delay(time: Long) {
2929
if (time <= 0) return // don't delay
3030
return suspendCancellableCoroutine { scheduleResumeAfterDelay(time, it) }
3131
}
@@ -45,7 +45,7 @@ public interface Delay {
4545
* with(continuation) { resumeUndispatchedWith(Unit) }
4646
* ```
4747
*/
48-
fun scheduleResumeAfterDelay(timeMillis: Long, continuation: CancellableContinuation<Unit>)
48+
public fun scheduleResumeAfterDelay(timeMillis: Long, continuation: CancellableContinuation<Unit>)
4949

5050
/**
5151
* Schedules invocation of a specified [block] after a specified delay [timeMillis].
@@ -54,7 +54,7 @@ public interface Delay {
5454
*
5555
* This implementation uses a built-in single-threaded scheduled executor service.
5656
*/
57-
fun invokeOnTimeout(timeMillis: Long, block: Runnable): DisposableHandle =
57+
public fun invokeOnTimeout(timeMillis: Long, block: Runnable): DisposableHandle =
5858
DefaultDelay.invokeOnTimeout(timeMillis, block)
5959
}
6060

@@ -87,7 +87,7 @@ public suspend fun delay(timeMillis: Long) {
8787
* Implementation note: how exactly time is tracked is an implementation detail of [CoroutineDispatcher] in the context.
8888
*/
8989
@ExperimentalTime
90-
public suspend fun delay(duration: Duration) = delay(duration.toDelayMillis())
90+
public suspend fun delay(duration: Duration): Unit = delay(duration.toDelayMillis())
9191

9292
/** Returns [Delay] implementation of the given context */
9393
internal val CoroutineContext.delay: Delay get() = get(ContinuationInterceptor) as? Delay ?: DefaultDelay

kotlinx-coroutines-core/common/src/Job.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public interface Job : CoroutineContext.Element {
167167
* @suppress This method implements old version of JVM ABI. Use [cancel].
168168
*/
169169
@Deprecated(level = DeprecationLevel.HIDDEN, message = "Since 1.2.0, binary compatibility with versions <= 1.1.x")
170-
public fun cancel() = cancel(null)
170+
public fun cancel(): Unit = cancel(null)
171171

172172
/**
173173
* @suppress This method has bad semantics when cause is not a [CancellationException]. Use [cancel].
@@ -337,7 +337,7 @@ public interface Job : CoroutineContext.Element {
337337
"Job is a coroutine context element and `+` is a set-sum operator for coroutine contexts. " +
338338
"The job to the right of `+` just replaces the job the left of `+`.",
339339
level = DeprecationLevel.ERROR)
340-
public operator fun plus(other: Job) = other
340+
public operator fun plus(other: Job): Job = other
341341
}
342342

343343
/**
@@ -382,7 +382,7 @@ public interface DisposableHandle {
382382
*/
383383
@Suppress("FunctionName")
384384
@InternalCoroutinesApi
385-
public inline fun DisposableHandle(crossinline block: () -> Unit) =
385+
public inline fun DisposableHandle(crossinline block: () -> Unit): DisposableHandle =
386386
object : DisposableHandle {
387387
override fun dispose() {
388388
block()
@@ -496,7 +496,7 @@ public fun Job.cancelChildren(cause: CancellationException? = null) {
496496
* @suppress This method implements old version of JVM ABI. Use [cancel].
497497
*/
498498
@Deprecated(level = DeprecationLevel.HIDDEN, message = "Since 1.2.0, binary compatibility with versions <= 1.1.x")
499-
public fun Job.cancelChildren() = cancelChildren(null)
499+
public fun Job.cancelChildren(): Unit = cancelChildren(null)
500500

501501
/**
502502
* @suppress This method has bad semantics when cause is not a [CancellationException]. Use [Job.cancelChildren].
@@ -539,7 +539,7 @@ public fun CoroutineContext.cancel(cause: CancellationException? = null) {
539539
* @suppress This method implements old version of JVM ABI. Use [CoroutineContext.cancel].
540540
*/
541541
@Deprecated(level = DeprecationLevel.HIDDEN, message = "Since 1.2.0, binary compatibility with versions <= 1.1.x")
542-
public fun CoroutineContext.cancel() = cancel(null)
542+
public fun CoroutineContext.cancel(): Unit = cancel(null)
543543

544544
/**
545545
* Ensures that current job is [active][Job.isActive].
@@ -605,7 +605,7 @@ public fun CoroutineContext.cancelChildren(cause: CancellationException? = null)
605605
* @suppress This method implements old version of JVM ABI. Use [CoroutineContext.cancelChildren].
606606
*/
607607
@Deprecated(level = DeprecationLevel.HIDDEN, message = "Since 1.2.0, binary compatibility with versions <= 1.1.x")
608-
public fun CoroutineContext.cancelChildren() = cancelChildren(null)
608+
public fun CoroutineContext.cancelChildren(): Unit = cancelChildren(null)
609609

610610
/**
611611
* @suppress This method has bad semantics when cause is not a [CancellationException]. Use [CoroutineContext.cancelChildren].

kotlinx-coroutines-core/common/src/JobSupport.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
652652
* Makes this [Job] cancelled with a specified [cause].
653653
* It is used in [AbstractCoroutine]-derived classes when there is an internal failure.
654654
*/
655-
public fun cancelCoroutine(cause: Throwable?) = cancelImpl(cause)
655+
public fun cancelCoroutine(cause: Throwable?): Boolean = cancelImpl(cause)
656656

657657
// cause is Throwable or ParentJob when cancelChild was invoked
658658
// returns true is exception was handled, false otherwise

kotlinx-coroutines-core/common/src/channels/Broadcast.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import kotlin.native.concurrent.*
3939
*
4040
* @param start coroutine start option. The default value is [CoroutineStart.LAZY].
4141
*/
42-
fun <E> ReceiveChannel<E>.broadcast(
42+
public fun <E> ReceiveChannel<E>.broadcast(
4343
capacity: Int = 1,
4444
start: CoroutineStart = CoroutineStart.LAZY
4545
): BroadcastChannel<E> {

kotlinx-coroutines-core/common/src/channels/Channel.kt

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
package kotlinx.coroutines.channels
88

99
import kotlinx.coroutines.*
10+
import kotlinx.coroutines.channels.Channel.Factory.BUFFERED
11+
import kotlinx.coroutines.channels.Channel.Factory.CHANNEL_DEFAULT_CAPACITY
1012
import kotlinx.coroutines.channels.Channel.Factory.CONFLATED
1113
import kotlinx.coroutines.channels.Channel.Factory.RENDEZVOUS
1214
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
13-
import kotlinx.coroutines.channels.Channel.Factory.BUFFERED
14-
import kotlinx.coroutines.channels.Channel.Factory.CHANNEL_DEFAULT_CAPACITY
15-
import kotlinx.coroutines.internal.systemProp
15+
import kotlinx.coroutines.internal.*
1616
import kotlinx.coroutines.selects.*
17-
import kotlin.jvm.*
1817
import kotlin.internal.*
18+
import kotlin.jvm.*
1919

2020
/**
2121
* Sender's interface to [Channel].
@@ -314,7 +314,7 @@ public interface ReceiveChannel<out E> {
314314
* @suppress This method implements old version of JVM ABI. Use [cancel].
315315
*/
316316
@Deprecated(level = DeprecationLevel.HIDDEN, message = "Since 1.2.0, binary compatibility with versions <= 1.1.x")
317-
public fun cancel() = cancel(null)
317+
public fun cancel(): Unit = cancel(null)
318318

319319
/**
320320
* @suppress This method has bad semantics when cause is not a [CancellationException]. Use [cancel].
@@ -517,25 +517,25 @@ public interface Channel<E> : SendChannel<E>, ReceiveChannel<E> {
517517
/**
518518
* Requests a channel with an unlimited capacity buffer in the `Channel(...)` factory function
519519
*/
520-
public const val UNLIMITED = Int.MAX_VALUE
520+
public const val UNLIMITED: Int = Int.MAX_VALUE
521521

522522
/**
523523
* Requests a rendezvous channel in the `Channel(...)` factory function &mdash; a `RendezvousChannel` gets created.
524524
*/
525-
public const val RENDEZVOUS = 0
525+
public const val RENDEZVOUS: Int = 0
526526

527527
/**
528528
* Requests a conflated channel in the `Channel(...)` factory function &mdash; a `ConflatedChannel` gets created.
529529
*/
530-
public const val CONFLATED = -1
530+
public const val CONFLATED: Int = -1
531531

532532
/**
533533
* Requests a buffered channel with the default buffer capacity in the `Channel(...)` factory function &mdash;
534534
* an `ArrayChannel` gets created with the default capacity.
535535
* The default capacity is 64 and can be overridden by setting
536536
* [DEFAULT_BUFFER_PROPERTY_NAME] on JVM.
537537
*/
538-
public const val BUFFERED = -2
538+
public const val BUFFERED: Int = -2
539539

540540
// only for internal use, cannot be used with Channel(...)
541541
internal const val OPTIONAL_CHANNEL = -3
@@ -544,7 +544,7 @@ public interface Channel<E> : SendChannel<E>, ReceiveChannel<E> {
544544
* Name of the property that defines the default channel capacity when
545545
* [BUFFERED] is used as parameter in `Channel(...)` factory function.
546546
*/
547-
public const val DEFAULT_BUFFER_PROPERTY_NAME = "kotlinx.coroutines.channels.defaultBuffer"
547+
public const val DEFAULT_BUFFER_PROPERTY_NAME: String = "kotlinx.coroutines.channels.defaultBuffer"
548548

549549
internal val CHANNEL_DEFAULT_CAPACITY = systemProp(DEFAULT_BUFFER_PROPERTY_NAME,
550550
64, 1, UNLIMITED - 1

kotlinx-coroutines-core/common/src/channels/Channels.common.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public fun <E : Any> ReceiveChannel<E>.onReceiveOrNull(): SelectClause1<E?> {
8484
* See [issue #254](https://github.com/Kotlin/kotlinx.coroutines/issues/254).
8585
*/
8686
@ObsoleteCoroutinesApi
87-
public suspend inline fun <E> BroadcastChannel<E>.consumeEach(action: (E) -> Unit) =
87+
public suspend inline fun <E> BroadcastChannel<E>.consumeEach(action: (E) -> Unit): Unit =
8888
consume {
8989
for (element in this) action(element)
9090
}
@@ -175,7 +175,7 @@ public inline fun <E, R> ReceiveChannel<E>.consume(block: ReceiveChannel<E>.() -
175175
* This function [consumes][ReceiveChannel.consume] all elements of the original [ReceiveChannel].
176176
*/
177177
@ExperimentalCoroutinesApi // since 1.3.0, tentatively graduates in 1.4.0
178-
public suspend inline fun <E> ReceiveChannel<E>.consumeEach(action: (E) -> Unit) =
178+
public suspend inline fun <E> ReceiveChannel<E>.consumeEach(action: (E) -> Unit): Unit =
179179
consume {
180180
for (e in this) action(e)
181181
}

kotlinx-coroutines-core/common/src/channels/ConflatedBroadcastChannel.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ConflatedBroadcastChannel<E>() : BroadcastChannel<E> {
3737
* It is as a shortcut to creating an instance with a default constructor and
3838
* immediately sending an element: `ConflatedBroadcastChannel().apply { offer(value) }`.
3939
*/
40-
constructor(value: E) : this() {
40+
public constructor(value: E) : this() {
4141
_state.lazySet(State<E>(value, null))
4242
}
4343

kotlinx-coroutines-core/common/src/channels/Produce.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public interface ProducerScope<in E> : CoroutineScope, SendChannel<E> {
2222
* All the [SendChannel] functions on this interface delegate to
2323
* the channel instance returned by this property.
2424
*/
25-
val channel: SendChannel<E>
25+
public val channel: SendChannel<E>
2626
}
2727

2828
/**

kotlinx-coroutines-core/common/src/flow/Channels.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
2424
* See [consumeEach][ReceiveChannel.consumeEach].
2525
*/
2626
@ExperimentalCoroutinesApi // since version 1.3.0
27-
public suspend fun <T> FlowCollector<T>.emitAll(channel: ReceiveChannel<T>) =
27+
public suspend fun <T> FlowCollector<T>.emitAll(channel: ReceiveChannel<T>): Unit =
2828
emitAllImpl(channel, consume = true)
2929

3030
private suspend fun <T> FlowCollector<T>.emitAllImpl(channel: ReceiveChannel<T>, consume: Boolean) {

kotlinx-coroutines-core/common/src/flow/Migration.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
@file:JvmMultifileClass
66
@file:JvmName("FlowKt")
7-
@file:Suppress("unused", "DeprecatedCallableAddReplaceWith", "UNUSED_PARAMETER")
7+
@file:Suppress("unused", "DeprecatedCallableAddReplaceWith", "UNUSED_PARAMETER", "NO_EXPLICIT_RETURN_TYPE_IN_API_MODE")
88

99
package kotlinx.coroutines.flow
1010

0 commit comments

Comments
 (0)