Skip to content

Commit 79a2868

Browse files
committed
Added deprecated (with error level) plus operators on Job and CoroutineDispatcher to catch potential problem with their incorrect use at compile time
1 parent ea4a51b commit 79a2868

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/CoroutineDispatcher.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ public abstract class CoroutineDispatcher :
3636

3737
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> =
3838
DispatchedContinuation<T>(this, continuation)
39+
40+
@Suppress("DeprecatedCallableAddReplaceWith")
41+
@Deprecated(message = "Operator '+' on two CoroutineDispatcher objects is meaningless. " +
42+
"CoroutineDispatcher is a coroutine context element and `+` is a set-sum operator for coroutine contexts. " +
43+
"The dispatcher to the right of `+` just replaces the dispacher the left of `+`.",
44+
level = DeprecationLevel.ERROR)
45+
public operator fun plus(other: CoroutineDispatcher) = other
3946
}
4047

4148
internal class DispatchedContinuation<T>(

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Job.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ public interface Job : CoroutineContext.Element {
6868
*/
6969
public fun cancel(reason: Throwable? = null): Boolean
7070

71+
@Suppress("DeprecatedCallableAddReplaceWith")
72+
@Deprecated(message = "Operator '+' on two Job objects is meaningless. " +
73+
"Job is a coroutine context element and `+` is a set-sum operator for coroutine contexts. " +
74+
"The job to the right of `+` just replaces the job the left of `+`.",
75+
level = DeprecationLevel.ERROR)
76+
public operator fun plus(other: Job) = other
77+
7178
/**
7279
* Registration object for [onCompletion]. It can be used to [unregister] if needed.
7380
* There is no need to unregister after completion.

0 commit comments

Comments
 (0)