Skip to content

Commit 5417e3d

Browse files
authored
Warn when SharedFlow.last() is called (#4468)
Fixes #3275 Also removes an unnecessary suppress (minor)
1 parent 62bf21c commit 5417e3d

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

kotlinx-coroutines-core/api/kotlinx-coroutines-core.klib.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.channels/ReceiveC
11451145
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.flow/Flow<#A>).kotlinx.coroutines.flow/collect(crossinline kotlin.coroutines/SuspendFunction1<#A, kotlin/Unit>) // kotlinx.coroutines.flow/collect|[email protected]<0:0>(kotlin.coroutines.SuspendFunction1<0:0,kotlin.Unit>){0§<kotlin.Any?>}[0]
11461146
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.flow/Flow<#A>).kotlinx.coroutines.flow/collectIndexed(crossinline kotlin.coroutines/SuspendFunction2<kotlin/Int, #A, kotlin/Unit>) // kotlinx.coroutines.flow/collectIndexed|[email protected]<0:0>(kotlin.coroutines.SuspendFunction2<kotlin.Int,0:0,kotlin.Unit>){0§<kotlin.Any?>}[0]
11471147
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.flow/SharedFlow<#A>).kotlinx.coroutines.flow/count(): kotlin/Int // kotlinx.coroutines.flow/count|[email protected]<0:0>(){0§<kotlin.Any?>}[0]
1148+
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.flow/SharedFlow<#A>).kotlinx.coroutines.flow/last(): #A // kotlinx.coroutines.flow/last|[email protected]<0:0>(){0§<kotlin.Any?>}[0]
11481149
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.flow/SharedFlow<#A>).kotlinx.coroutines.flow/toList(): kotlin.collections/List<#A> // kotlinx.coroutines.flow/toList|[email protected]<0:0>(){0§<kotlin.Any?>}[0]
11491150
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.flow/SharedFlow<#A>).kotlinx.coroutines.flow/toList(kotlin.collections/MutableList<#A>): kotlin/Nothing // kotlinx.coroutines.flow/toList|[email protected]<0:0>(kotlin.collections.MutableList<0:0>){0§<kotlin.Any?>}[0]
11501151
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.flow/SharedFlow<#A>).kotlinx.coroutines.flow/toSet(): kotlin.collections/Set<#A> // kotlinx.coroutines.flow/toSet|[email protected]<0:0>(){0§<kotlin.Any?>}[0]

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ public abstract class CoroutineDispatcher :
291291
* CoroutineDispatcher is a coroutine context element and `+` is a set-sum operator for coroutine contexts.
292292
* The dispatcher to the right of `+` just replaces the dispatcher to the left.
293293
*/
294-
@Suppress("DeprecatedCallableAddReplaceWith")
295294
@Deprecated(
296295
message = "Operator '+' on two CoroutineDispatcher objects is meaningless. " +
297296
"CoroutineDispatcher is a coroutine context element and `+` is a set-sum operator for coroutine contexts. " +

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ public interface Job : CoroutineContext.Element {
338338
* Job is a coroutine context element and `+` is a set-sum operator for coroutine contexts.
339339
* The job to the right of `+` just replaces the job the left of `+`.
340340
*/
341-
@Suppress("DeprecatedCallableAddReplaceWith")
342341
@Deprecated(message = "Operator '+' on two Job objects is meaningless. " +
343342
"Job is a coroutine context element and `+` is a set-sum operator for coroutine contexts. " +
344343
"The job to the right of `+` just replaces the job the left of `+`.",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import kotlin.coroutines.*
2222
* The parent will not wait for the child's completion, nor will be cancelled when the child crashed.
2323
*/
2424
@OptIn(InternalForInheritanceCoroutinesApi::class)
25-
@Suppress("DeprecatedCallableAddReplaceWith")
2625
public object NonCancellable : AbstractCoroutineContextElement(Job), Job {
2726

2827
private const val message = "NonCancellable can be used only as an argument for 'withContext', direct usages of its API are prohibited"

kotlinx-coroutines-core/common/src/flow/operators/Lint.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ public inline fun <T> SharedFlow<T>.retryWhen(noinline predicate: suspend FlowCo
134134
/**
135135
* @suppress
136136
*/
137-
@Suppress("DeprecatedCallableAddReplaceWith")
138137
@Deprecated(
139138
message = "SharedFlow never completes, so this terminal operation never completes.",
140139
level = DeprecationLevel.WARNING
@@ -156,7 +155,6 @@ public suspend inline fun <T> SharedFlow<T>.toList(destination: MutableList<T>):
156155
/**
157156
* @suppress
158157
*/
159-
@Suppress("DeprecatedCallableAddReplaceWith")
160158
@Deprecated(
161159
message = "SharedFlow never completes, so this terminal operation never completes.",
162160
level = DeprecationLevel.WARNING
@@ -178,11 +176,22 @@ public suspend inline fun <T> SharedFlow<T>.toSet(destination: MutableSet<T>): N
178176
/**
179177
* @suppress
180178
*/
181-
@Suppress("DeprecatedCallableAddReplaceWith")
182179
@Deprecated(
183180
message = "SharedFlow never completes, so this terminal operation never completes.",
184181
level = DeprecationLevel.WARNING
185182
)
186183
@InlineOnly
187184
public suspend inline fun <T> SharedFlow<T>.count(): Int =
188185
(this as Flow<T>).count()
186+
187+
/**
188+
* @suppress
189+
*/
190+
@Deprecated(
191+
message = "SharedFlow never completes, so this terminal operation never completes. " +
192+
"If you are using last() to imitate a subscriber, use collect() instead.",
193+
level = DeprecationLevel.WARNING,
194+
)
195+
@InlineOnly
196+
public suspend inline fun <T> SharedFlow<T>.last(): T =
197+
(this as Flow<T>).last()

0 commit comments

Comments
 (0)