Skip to content

Commit 4220ca2

Browse files
committed
Use toString implementation for continuations to leverage debug metadata
Fixes #679
1 parent 67222cb commit 4220ca2

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

core/kotlinx-coroutines-core/src/Debug.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,9 @@ internal val DEBUG = systemProp(DEBUG_PROPERTY_NAME).let { value ->
4141
internal actual val Any.hexAddress: String
4242
get() = Integer.toHexString(System.identityHashCode(this))
4343

44-
internal fun Any?.toSafeString(): String =
45-
try { toString() }
46-
catch (e: Throwable) { "toString() failed with $e" }
47-
48-
// **KLUDGE**: there is no reason to include continuation into debug string until the following ticket is resolved:
49-
// KT-18986 Debug-friendly toString implementation for CoroutineImpl
50-
// (the current string representation of continuation is useless and uses buggy reflection internals)
51-
// So, this function is a replacement that extract a usable information from continuation -> its class name, at least
5244
internal actual fun Continuation<*>.toDebugString(): String = when (this) {
5345
is DispatchedContinuation -> toString()
54-
else -> "${this::class.java.name}@$hexAddress"
46+
else -> "$this@$hexAddress"
5547
}
5648

5749
internal actual val Any.classSimpleName: String get() = this::class.java.simpleName
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.coroutines
6+
7+
import kotlin.coroutines.*
8+
import kotlin.test.*
9+
10+
class CancellableContinuationJvmTest : TestBase() {
11+
@Test
12+
fun testToString() = runTest {
13+
checkToString()
14+
}
15+
16+
private suspend fun checkToString() {
17+
suspendCancellableCoroutine<Unit> {
18+
it.resume(Unit)
19+
assertTrue(it.toString().contains("kotlinx/coroutines/CancellableContinuationJvmTest.checkToString(CancellableContinuationJvmTest.kt:16"))
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)