From 8a6821d53afc615cce669c11899426d302cef8f3 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 10 Nov 2015 23:27:58 +0300 Subject: [PATCH] Throw correct exception for zero increment. Deprecate public functions in progression utils. --- core/builtins/src/kotlin/internal/progressionUtil.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/builtins/src/kotlin/internal/progressionUtil.kt b/core/builtins/src/kotlin/internal/progressionUtil.kt index 68632d851ea..2ad25ef006b 100644 --- a/core/builtins/src/kotlin/internal/progressionUtil.kt +++ b/core/builtins/src/kotlin/internal/progressionUtil.kt @@ -50,13 +50,17 @@ private fun differenceModulo(a: Long, b: Long, c: Long): Long { * @return the final element of the progression * @suppress */ +@Deprecated("This function supports the compiler infrastructure and is not intended to be used directly from user code. It may become internal soon.") public fun getProgressionFinalElement(start: Int, end: Int, increment: Int): Int { if (increment > 0) { return end - differenceModulo(end, start, increment) } - else { + else if (increment < 0) { return end + differenceModulo(start, end, -increment) } + else { + throw IllegalArgumentException("Increment is zero.") + } } /** @@ -72,11 +76,15 @@ public fun getProgressionFinalElement(start: Int, end: Int, increment: Int): Int * @return the final element of the progression * @suppress */ +@Deprecated("This function supports the compiler infrastructure and is not intended to be used directly from user code. It may become internal soon.") public fun getProgressionFinalElement(start: Long, end: Long, increment: Long): Long { if (increment > 0) { return end - differenceModulo(end, start, increment) } - else { + else if (increment < 0) { return end + differenceModulo(start, end, -increment) } + else { + throw IllegalArgumentException("Increment is zero.") + } }