From fba22606e69962cecf5074dfbb9946cb5ed92cd2 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 15 Aug 2019 19:34:58 +0300 Subject: [PATCH] Introduce erroneous operators ClockMark.minus/compareTo(ClockMark) To provide a better diagnostic message on their misuse. --- libraries/stdlib/src/kotlin/time/Clock.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libraries/stdlib/src/kotlin/time/Clock.kt b/libraries/stdlib/src/kotlin/time/Clock.kt index e20c1c7e5de..3e2853b7ae5 100644 --- a/libraries/stdlib/src/kotlin/time/Clock.kt +++ b/libraries/stdlib/src/kotlin/time/Clock.kt @@ -71,6 +71,20 @@ public abstract class ClockMark { public fun hasNotPassedNow(): Boolean = elapsedNow().isNegative() } + +@ExperimentalTime +@SinceKotlin("1.3") +@kotlin.internal.InlineOnly +@Deprecated("Subtracting one ClockMark from another is not a well defined operation because these clock marks could have been obtained from the different clocks.", level = DeprecationLevel.ERROR) +public inline operator fun ClockMark.minus(other: ClockMark): Duration = throw Error("Operation is disallowed.") + +@ExperimentalTime +@SinceKotlin("1.3") +@kotlin.internal.InlineOnly +@Deprecated("Comparing one ClockMark to another is not a well defined operation because these clock marks could have been obtained from the different clocks.", level = DeprecationLevel.ERROR) +public inline operator fun ClockMark.compareTo(other: ClockMark): Int = throw Error("Operation is disallowed.") + + @ExperimentalTime private class AdjustedClockMark(val mark: ClockMark, val adjustment: Duration) : ClockMark() { override fun elapsedNow(): Duration = mark.elapsedNow() - adjustment