Skip to content

Commit 9942a30

Browse files
committed
Fix expect/actual mismatched member scope for open expect compilation errors
Those are compilation errors introduced in Kotlin 1.9.20 in scope of https://youtrack.jetbrains.com/issue/KT-22841
1 parent db57e08 commit 9942a30

File tree

8 files changed

+85
-3
lines changed

8 files changed

+85
-3
lines changed

kotlinx-coroutines-core/concurrent/src/CompletionHandler.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ package kotlinx.coroutines
66

77
import kotlinx.coroutines.internal.*
88

9+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
10+
// New 'CompletionHandler` supertype is added compared to the expect declaration.
11+
// Probably we can add it to JS and common too, to avoid the suppression/opt-in
12+
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER")
913
internal actual abstract class CompletionHandlerBase actual constructor() : LockFreeLinkedListNode(), CompletionHandler {
1014
actual abstract override fun invoke(cause: Throwable?)
1115
}
1216

1317
internal actual inline val CompletionHandlerBase.asHandler: CompletionHandler get() = this
1418

19+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
20+
// New 'CompletionHandler` supertype is added compared to the expect declaration.
21+
// Probably we can add it to JS and common too, to avoid the suppression/opt-in
22+
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER")
1523
internal actual abstract class CancelHandlerBase actual constructor() : CompletionHandler {
1624
actual abstract override fun invoke(cause: Throwable?)
1725
}

kotlinx-coroutines-core/concurrent/src/internal/LockFreeLinkedList.kt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ internal val CONDITION_FALSE: Any = Symbol("CONDITION_FALSE")
4242
*
4343
* @suppress **This is unstable API and it is subject to change.**
4444
*/
45-
@Suppress("LeakingThis")
45+
@Suppress(
46+
"LeakingThis",
47+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
48+
"ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER"
49+
)
4650
@InternalCoroutinesApi
4751
public actual open class LockFreeLinkedListNode {
4852
private val _next = atomic<Any>(this) // Node | Removed | OpDescriptor
@@ -68,14 +72,20 @@ public actual open class LockFreeLinkedListNode {
6872
}
6973
}
7074

75+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
76+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
7177
@PublishedApi
7278
internal inline fun makeCondAddOp(node: Node, crossinline condition: () -> Boolean): CondAddOp =
7379
object : CondAddOp(node) {
7480
override fun prepare(affected: Node): Any? = if (condition()) null else CONDITION_FALSE
7581
}
7682

83+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
84+
@Suppress("MODALITY_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION")
7785
public actual open val isRemoved: Boolean get() = next is Removed
7886

87+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
88+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
7989
// LINEARIZABLE. Returns Node | Removed
8090
public val next: Any get() {
8191
_next.loop { next ->
@@ -166,6 +176,8 @@ public actual open class LockFreeLinkedListNode {
166176
* Where `==>` denotes linearization point.
167177
* Returns `false` if `next` was not following `this` node.
168178
*/
179+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
180+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
169181
@PublishedApi
170182
internal fun addNext(node: Node, next: Node): Boolean {
171183
node._prev.lazySet(this)
@@ -176,6 +188,8 @@ public actual open class LockFreeLinkedListNode {
176188
return true
177189
}
178190

191+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
192+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
179193
// returns UNDECIDED, SUCCESS or FAILURE
180194
@PublishedApi
181195
internal fun tryCondAddNext(node: Node, next: Node, condAdd: CondAddOp): Int {
@@ -199,6 +213,8 @@ public actual open class LockFreeLinkedListNode {
199213
public actual open fun remove(): Boolean =
200214
removeOrNext() == null
201215

216+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
217+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
202218
// returns null if removed successfully or next node if this node is already removed
203219
@PublishedApi
204220
internal fun removeOrNext(): Node? {
@@ -255,6 +271,8 @@ public actual open class LockFreeLinkedListNode {
255271
}
256272
}
257273

274+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
275+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
258276
protected open fun nextIfRemoved(): Node? = (next as? Removed)?.ref
259277

260278
/**
@@ -311,6 +329,8 @@ public actual open class LockFreeLinkedListNode {
311329
}
312330
}
313331

332+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
333+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
314334
internal fun validateNode(prev: Node, next: Node) {
315335
assert { prev === this._prev.value }
316336
assert { next === this._next.value }
@@ -331,6 +351,8 @@ internal fun Any.unwrap(): Node = (this as? Removed)?.ref ?: this as Node
331351
*
332352
* @suppress **This is unstable API and it is subject to change.**
333353
*/
354+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
355+
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER")
334356
public actual open class LockFreeLinkedListHead : LockFreeLinkedListNode() {
335357
public actual val isEmpty: Boolean get() = next === this
336358

@@ -352,6 +374,8 @@ public actual open class LockFreeLinkedListHead : LockFreeLinkedListNode() {
352374
override val isRemoved: Boolean get() = false
353375
override fun nextIfRemoved(): Node? = null
354376

377+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
378+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
355379
internal fun validate() {
356380
var prev: Node = this
357381
var cur: Node = next as Node

kotlinx-coroutines-core/js/src/internal/LinkedList.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ import kotlinx.coroutines.*
1010

1111
private typealias Node = LinkedListNode
1212
/** @suppress **This is unstable API and it is subject to change.** */
13-
@Suppress("NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS") // :TODO: Remove when fixed: https://youtrack.jetbrains.com/issue/KT-23703
13+
@Suppress(
14+
// :TODO: Remove when fixed: https://youtrack.jetbrains.com/issue/KT-23703
15+
"NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS",
16+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
17+
"ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER",
18+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
19+
"ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER"
20+
)
1421
public actual typealias LockFreeLinkedListNode = LinkedListNode
1522

1623
/** @suppress **This is unstable API and it is subject to change.** */

kotlinx-coroutines-core/jvm/src/EventLoop.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import kotlinx.coroutines.Runnable
88
import kotlinx.coroutines.scheduling.*
99
import kotlinx.coroutines.scheduling.CoroutineScheduler
1010

11+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
12+
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER")
1113
internal actual abstract class EventLoopImplPlatform: EventLoop() {
14+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
15+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
1216
protected abstract val thread: Thread
1317

1418
protected actual fun unpark() {
@@ -17,6 +21,8 @@ internal actual abstract class EventLoopImplPlatform: EventLoop() {
1721
unpark(thread)
1822
}
1923

24+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
25+
@Suppress("MODALITY_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION")
2026
protected actual open fun reschedule(now: Long, delayedTask: EventLoopImplBase.DelayedTask) {
2127
DefaultExecutor.schedule(now, delayedTask)
2228
}

kotlinx-coroutines-core/jvm/src/Executors.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public abstract class ExecutorCoroutineDispatcher: CoroutineDispatcher(), Closea
3737
public abstract override fun close()
3838
}
3939

40+
@Suppress(
41+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
42+
"ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER",
43+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
44+
"ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER"
45+
)
4046
@ExperimentalCoroutinesApi
4147
public actual typealias CloseableCoroutineDispatcher = ExecutorCoroutineDispatcher
4248

kotlinx-coroutines-core/jvm/src/SchedulerTask.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ package kotlinx.coroutines
66

77
import kotlinx.coroutines.scheduling.*
88

9+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
10+
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER")
911
internal actual typealias SchedulerTask = Task
1012

13+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
14+
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER")
1115
internal actual typealias SchedulerTaskContext = TaskContext
1216

1317
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")

kotlinx-coroutines-core/jvm/test/TestBase.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public actual typealias TestResult = Unit
5454
* }
5555
* ```
5656
*/
57-
@Suppress("NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS") // Counterpart for @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
57+
@Suppress(
58+
// Counterpart for @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
59+
"NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS",
60+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
61+
"ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER"
62+
)
5863
public actual open class TestBase(private var disableOutCheck: Boolean) {
5964

6065
actual constructor(): this(false)
@@ -80,11 +85,14 @@ public actual open class TestBase(private var disableOutCheck: Boolean) {
8085
* Throws [IllegalStateException] like `error` in stdlib, but also ensures that the test will not
8186
* complete successfully even if this exception is consumed somewhere in the test.
8287
*/
88+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
8389
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
8490
public actual fun error(message: Any, cause: Throwable? = null): Nothing {
8591
throw makeError(message, cause)
8692
}
8793

94+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
95+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
8896
public fun hasError() = error.get() != null
8997

9098
private fun makeError(message: Any, cause: Throwable? = null): IllegalStateException =
@@ -108,6 +116,8 @@ public actual open class TestBase(private var disableOutCheck: Boolean) {
108116
* Throws [IllegalStateException] when `value` is false like `check` in stdlib, but also ensures that the
109117
* test will not complete successfully even if this exception is consumed somewhere in the test.
110118
*/
119+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
120+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
111121
public inline fun check(value: Boolean, lazyMessage: () -> Any) {
112122
if (!value) error(lazyMessage())
113123
}
@@ -155,12 +165,16 @@ public actual open class TestBase(private var disableOutCheck: Boolean) {
155165
}
156166
})
157167

168+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
169+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
158170
fun println(message: Any?) {
159171
if (disableOutCheck) kotlin.io.println(message)
160172
else previousOut.println(message)
161173
}
162174

163175
@Before
176+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
177+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
164178
fun before() {
165179
initPoolsBeforeTest()
166180
threadsBefore = currentThreads()
@@ -176,6 +190,8 @@ public actual open class TestBase(private var disableOutCheck: Boolean) {
176190
}
177191
}
178192

193+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
194+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
179195
@After
180196
fun onCompletion() {
181197
// onCompletion should not throw exceptions before it finishes all cleanup, so that other tests always
@@ -203,16 +219,21 @@ public actual open class TestBase(private var disableOutCheck: Boolean) {
203219
error.get()?.let { throw it }
204220
}
205221

222+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
223+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
206224
fun initPoolsBeforeTest() {
207225
DefaultScheduler.usePrivateScheduler()
208226
}
209227

228+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
229+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
210230
fun shutdownPoolsAfterTest() {
211231
DefaultScheduler.shutdown(SHUTDOWN_TIMEOUT)
212232
DefaultExecutor.shutdownForTests(SHUTDOWN_TIMEOUT)
213233
DefaultScheduler.restore()
214234
}
215235

236+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
216237
@Suppress("ACTUAL_WITHOUT_EXPECT", "ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
217238
public actual fun runTest(
218239
expected: ((Throwable) -> Boolean)? = null,
@@ -247,12 +268,16 @@ public actual open class TestBase(private var disableOutCheck: Boolean) {
247268
error("Too few unhandled exceptions $exCount, expected ${unhandled.size}")
248269
}
249270

271+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
272+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
250273
protected inline fun <reified T: Throwable> assertFailsWith(block: () -> Unit): T {
251274
val result = runCatching(block)
252275
assertTrue(result.exceptionOrNull() is T, "Expected ${T::class}, but had $result")
253276
return result.exceptionOrNull()!! as T
254277
}
255278

279+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
280+
@Suppress("NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION")
256281
protected suspend fun currentDispatcher() = coroutineContext[ContinuationInterceptor]!!
257282
}
258283

kotlinx-coroutines-core/native/src/internal/Synchronized.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import kotlinx.atomicfu.locks.withLock as withLock2
1111
* @suppress **This an internal API and should not be used from general code.**
1212
*/
1313
@InternalCoroutinesApi
14+
// fixme replace the suppress with AllowDifferentMembersInActual once stdlib is updated to 1.9.20 https://github.com/Kotlin/kotlinx.coroutines/issues/3846
15+
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER")
1416
public actual typealias SynchronizedObject = kotlinx.atomicfu.locks.SynchronizedObject
1517

1618
/**

0 commit comments

Comments
 (0)