diff --git a/core/builtins/src/kotlin/Progressions.kt b/core/builtins/src/kotlin/Progressions.kt index 0fc54d47814..60be9e5c936 100644 --- a/core/builtins/src/kotlin/Progressions.kt +++ b/core/builtins/src/kotlin/Progressions.kt @@ -20,8 +20,8 @@ public open class CharProgression step: Int ) : Iterable { init { - if (step == 0) throw kotlin.IllegalArgumentException("Step must be non-zero") - else if (step == Int.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must have an inverse") + if (step == 0) throw kotlin.IllegalArgumentException("Step must be non-zero.") + if (step == Int.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must be greater than Int.MIN_VALUE to avoid overflow on negation.") } /** @@ -59,6 +59,8 @@ public open class CharProgression * The progression starts with the [rangeStart] value and goes toward the [rangeEnd] value not excluding it, with the specified [step]. * In order to go backwards the [step] must be negative. + * + * [step] must be greater than `Int.MIN_VALUE` and not equal to zero. */ public fun fromClosedRange(rangeStart: Char, rangeEnd: Char, step: Int): CharProgression = CharProgression(rangeStart, rangeEnd, step) } @@ -75,8 +77,8 @@ public open class IntProgression step: Int ) : Iterable { init { - if (step == 0) throw kotlin.IllegalArgumentException("Step must be non-zero") - else if (step == Int.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must have an inverse") + if (step == 0) throw kotlin.IllegalArgumentException("Step must be non-zero.") + if (step == Int.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must be greater than Int.MIN_VALUE to avoid overflow on negation.") } /** @@ -114,6 +116,8 @@ public open class IntProgression * The progression starts with the [rangeStart] value and goes toward the [rangeEnd] value not excluding it, with the specified [step]. * In order to go backwards the [step] must be negative. + * + * [step] must be greater than `Int.MIN_VALUE` and not equal to zero. */ public fun fromClosedRange(rangeStart: Int, rangeEnd: Int, step: Int): IntProgression = IntProgression(rangeStart, rangeEnd, step) } @@ -130,8 +134,8 @@ public open class LongProgression step: Long ) : Iterable { init { - if (step == 0L) throw kotlin.IllegalArgumentException("Step must be non-zero") - else if (step == Long.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must have an inverse") + if (step == 0L) throw kotlin.IllegalArgumentException("Step must be non-zero.") + if (step == Long.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must be greater than Long.MIN_VALUE to avoid overflow on negation.") } /** @@ -169,6 +173,8 @@ public open class LongProgression * The progression starts with the [rangeStart] value and goes toward the [rangeEnd] value not excluding it, with the specified [step]. * In order to go backwards the [step] must be negative. + * + * [step] must be greater than `Long.MIN_VALUE` and not equal to zero. */ public fun fromClosedRange(rangeStart: Long, rangeEnd: Long, step: Long): LongProgression = LongProgression(rangeStart, rangeEnd, step) } diff --git a/generators/builtins/progressions.kt b/generators/builtins/progressions.kt index c56f9a611a8..1651a92f432 100644 --- a/generators/builtins/progressions.kt +++ b/generators/builtins/progressions.kt @@ -35,13 +35,10 @@ class GenerateProgressions(out: PrintWriter) : BuiltInsSourceGenerator(out) { LONG -> "0L" else -> "0" } - val checkZero = """if (step == $zero) throw kotlin.IllegalArgumentException("Step must be non-zero")""" + val checkZero = """if (step == $zero) throw kotlin.IllegalArgumentException("Step must be non-zero.")""" - val minValue = when (kind) { - LONG -> "Long.MIN_VALUE" - else -> "Int.MIN_VALUE" - } - val checkMin = """else if (step == $minValue) throw kotlin.IllegalArgumentException("Step must have an inverse")""" + val stepMinValue = "$incrementType.MIN_VALUE" + val checkMin = """if (step == $stepMinValue) throw kotlin.IllegalArgumentException("Step must be greater than $stepMinValue to avoid overflow on negation.")""" val hashCode = "=\n" + when (kind) { CHAR -> @@ -103,6 +100,8 @@ public open class $progression * The progression starts with the [rangeStart] value and goes toward the [rangeEnd] value not excluding it, with the specified [step]. * In order to go backwards the [step] must be negative. + * + * [step] must be greater than `$stepMinValue` and not equal to zero. */ public fun fromClosedRange(rangeStart: $t, rangeEnd: $t, step: $incrementType): $progression = $progression(rangeStart, rangeEnd, step) }