From e799c921314256196ed1a8c6d7da689cd35a18d8 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 22 Jul 2015 00:47:44 +0300 Subject: [PATCH] Accept more generic range for coerceIn. --- libraries/stdlib/src/generated/_Comparables.kt | 12 ++++++------ .../kotlin-stdlib-gen/src/templates/Comparables.kt | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/stdlib/src/generated/_Comparables.kt b/libraries/stdlib/src/generated/_Comparables.kt index 060d310fef1..84c898519df 100644 --- a/libraries/stdlib/src/generated/_Comparables.kt +++ b/libraries/stdlib/src/generated/_Comparables.kt @@ -254,7 +254,7 @@ public fun > T.coerceIn(range: Range): T { * Ensures that this value lies in the specified [range]. * @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end. */ -public fun Byte.coerceIn(range: ByteRange): Byte { +public fun Byte.coerceIn(range: Range): Byte { if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") return if (this < range.start) range.start else if (this > range.end) range.end else this } @@ -263,7 +263,7 @@ public fun Byte.coerceIn(range: ByteRange): Byte { * Ensures that this value lies in the specified [range]. * @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end. */ -public fun Double.coerceIn(range: DoubleRange): Double { +public fun Double.coerceIn(range: Range): Double { if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") return if (this < range.start) range.start else if (this > range.end) range.end else this } @@ -272,7 +272,7 @@ public fun Double.coerceIn(range: DoubleRange): Double { * Ensures that this value lies in the specified [range]. * @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end. */ -public fun Float.coerceIn(range: FloatRange): Float { +public fun Float.coerceIn(range: Range): Float { if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") return if (this < range.start) range.start else if (this > range.end) range.end else this } @@ -281,7 +281,7 @@ public fun Float.coerceIn(range: FloatRange): Float { * Ensures that this value lies in the specified [range]. * @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end. */ -public fun Int.coerceIn(range: IntRange): Int { +public fun Int.coerceIn(range: Range): Int { if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") return if (this < range.start) range.start else if (this > range.end) range.end else this } @@ -290,7 +290,7 @@ public fun Int.coerceIn(range: IntRange): Int { * Ensures that this value lies in the specified [range]. * @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end. */ -public fun Long.coerceIn(range: LongRange): Long { +public fun Long.coerceIn(range: Range): Long { if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") return if (this < range.start) range.start else if (this > range.end) range.end else this } @@ -299,7 +299,7 @@ public fun Long.coerceIn(range: LongRange): Long { * Ensures that this value lies in the specified [range]. * @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end. */ -public fun Short.coerceIn(range: ShortRange): Short { +public fun Short.coerceIn(range: Range): Short { if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") return if (this < range.start) range.start else if (this > range.end) range.end else this } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt index f6a3b8eb67e..d3723b0119c 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt @@ -44,7 +44,7 @@ fun comparables(): List { } } - templates add f("coerceIn(range: TRange)") { + templates add f("coerceIn(range: Range)") { only(Primitives, Generic) only(numericPrimitives) returns("SELF")