diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2019-05-15 22:33:27 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2019-05-15 22:33:27 +0200 |
| commit | b0b1577ace36022faec1a4ed0369f1c1271d5ccd (patch) | |
| tree | 22744a52e9c7bb6d5b89abbbec05d6aa3db00c37 /odcsim-core | |
| parent | 720d1f433e0fed0ee48cbebdb8f995e5d5fc7405 (diff) | |
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.
Diffstat (limited to 'odcsim-core')
3 files changed, 10 insertions, 2 deletions
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<T : Any> { */ fun isSync(target: ActorRef<*>): Boolean } + +/** + * Unsafe helper method for widening the type accepted by this [ActorContext]. + */ +fun <U : Any, T : U> ActorContext<T>.unsafeCast(): ActorContext<U> { + @Suppress("UNCHECKED_CAST") + return this as ActorContext<U> +} 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<in T : Any> : Comparable<ActorRef<*>>, Serializable { /** * Unsafe helper method for widening the type accepted by this [ActorRef]. */ -fun <U : Any, T : U> ActorRef<T>.unsafeUpcast(): ActorRef<U> { +fun <U : Any, T : U> ActorRef<T>.unsafeCast(): ActorRef<U> { @Suppress("UNCHECKED_CAST") return this as ActorRef<U> } 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<ActorContext<Unit>>() val behavior = suspending<Unit> { - suspendCoroutine<Unit> { cont -> } + suspendCoroutine<Unit> {} stopped() } val interpreter = BehaviorInterpreter(behavior) |
