Skip to content

Commit 1f5ab53

Browse files
hrachqwwdfsad
authored andcommitted
flow: fix recursion in combineTransform<T1, T2, R>()
1 parent 9acde74 commit 1f5ab53

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ public fun <T1, T2, R> combineTransform(
106106
flow: Flow<T1>,
107107
flow2: Flow<T2>,
108108
@BuilderInference transform: suspend FlowCollector<R>.(a: T1, b: T2) -> Unit
109-
): Flow<R> = combineTransform(flow, flow2, transform)
109+
): Flow<R> = combineTransform(flow, flow2) { args: Array<*> ->
110+
transform(
111+
args[0] as T1,
112+
args[1] as T2
113+
)
114+
}
110115

111116
/**
112117
* Returns a [Flow] whose values are generated with [transform] function by combining

kotlinx-coroutines-core/common/test/flow/operators/CombineTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ class CombineIterableTest : CombineTestBase() {
260260
combineOriginal(listOf(this, other)) { args -> transform(args[0] as T1, args[1] as T2) }
261261
}
262262

263+
class CombineTransformAdapterTest : CombineTestBase() {
264+
override fun <T1, T2, R> Flow<T1>.combineLatest(other: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R> =
265+
combineTransformOriginal(flow = this, flow2 = other) { a1, a2 -> emit(transform(a1, a2)) }
266+
}
267+
263268
class CombineTransformVarargAdapterTest : CombineTestBase() {
264269
override fun <T1, T2, R> Flow<T1>.combineLatest(other: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R> =
265270
combineTransformOriginal(this, other) { args: Array<Any?> -> emit(transform(args[0] as T1, args[1] as T2)) }

0 commit comments

Comments
 (0)