From b0b1577ace36022faec1a4ed0369f1c1271d5ccd Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 15 May 2019 22:33:27 +0200 Subject: feat: Add unsafe helper method for casting ActorContext This change adds a helper method for ActorContext to unsafely cast it to an ActorContext of different type. --- odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorContext.kt | 8 ++++++++ odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt | 2 +- odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) (limited to 'odcsim-core') diff --git a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorContext.kt b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorContext.kt index f8128490..dc6ca7ec 100644 --- a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorContext.kt +++ b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorContext.kt @@ -165,3 +165,11 @@ interface ActorContext { */ fun isSync(target: ActorRef<*>): Boolean } + +/** + * Unsafe helper method for widening the type accepted by this [ActorContext]. + */ +fun ActorContext.unsafeCast(): ActorContext { + @Suppress("UNCHECKED_CAST") + return this as ActorContext +} diff --git a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt index 251d0669..45fc756e 100644 --- a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt +++ b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt @@ -44,7 +44,7 @@ interface ActorRef : Comparable>, Serializable { /** * Unsafe helper method for widening the type accepted by this [ActorRef]. */ -fun ActorRef.unsafeUpcast(): ActorRef { +fun ActorRef.unsafeCast(): ActorRef { @Suppress("UNCHECKED_CAST") return this as ActorRef } diff --git a/odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt b/odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt index d057024c..af7619e6 100644 --- a/odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt +++ b/odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt @@ -53,7 +53,7 @@ internal class CoroutinesTest { fun `should be able to invoke regular suspend methods`() { val ctx = mock>() val behavior = suspending { - suspendCoroutine { cont -> } + suspendCoroutine {} stopped() } val interpreter = BehaviorInterpreter(behavior) -- cgit v1.2.3