Skip to content

Commit ea4cd45

Browse files
konrad-kaminskielizarov
authored andcommitted
equals should not be used on withTimeout results
Fixes #212.
1 parent 9af2571 commit ea4cd45

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

common/kotlinx-coroutines-core-common/src/main/kotlin/kotlinx/coroutines/experimental/intrinsics/Undispatched.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private inline fun <T> AbstractCoroutine<T>.undispatchedResult(startBlock: () ->
8383
CompletedExceptionally(e)
8484
}
8585
return when {
86-
result == COROUTINE_SUSPENDED -> COROUTINE_SUSPENDED
86+
result === COROUTINE_SUSPENDED -> COROUTINE_SUSPENDED
8787
makeCompletingOnce(result, MODE_IGNORE) -> {
8888
if (result is CompletedExceptionally) throw result.exception else result
8989
}

common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonWithTimeoutTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,20 @@ class CommonWithTimeoutTest : TestBase() {
109109
}
110110
finish(5)
111111
}
112+
113+
@Test
114+
fun testBadClass() = runTest {
115+
val bad = BadClass()
116+
val result = withTimeout(100) {
117+
bad
118+
}
119+
assertSame(bad, result)
120+
}
121+
122+
class BadClass {
123+
override fun equals(other: Any?): Boolean = error("Should not be called")
124+
override fun hashCode(): Int = error("Should not be called")
125+
override fun toString(): String = error("Should not be called")
126+
}
112127
}
113128

0 commit comments

Comments
 (0)