diff --git a/libraries/stdlib/common/src/generated/_Ranges.kt b/libraries/stdlib/common/src/generated/_Ranges.kt index 5f1c76fcf7b..792cb5ad3c3 100644 --- a/libraries/stdlib/common/src/generated/_Ranges.kt +++ b/libraries/stdlib/common/src/generated/_Ranges.kt @@ -120,6 +120,7 @@ public operator fun ClosedRange.contains(value: Byte): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("doubleRangeContains") public operator fun ClosedRange.contains(value: Byte): Boolean { return contains(value.toDouble()) @@ -128,6 +129,7 @@ public operator fun ClosedRange.contains(value: Byte): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("floatRangeContains") public operator fun ClosedRange.contains(value: Byte): Boolean { return contains(value.toFloat()) @@ -136,6 +138,7 @@ public operator fun ClosedRange.contains(value: Byte): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("intRangeContains") public operator fun ClosedRange.contains(value: Double): Boolean { return value.toIntExactOrNull().let { if (it != null) contains(it) else false } @@ -144,6 +147,7 @@ public operator fun ClosedRange.contains(value: Double): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("longRangeContains") public operator fun ClosedRange.contains(value: Double): Boolean { return value.toLongExactOrNull().let { if (it != null) contains(it) else false } @@ -152,6 +156,7 @@ public operator fun ClosedRange.contains(value: Double): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("byteRangeContains") public operator fun ClosedRange.contains(value: Double): Boolean { return value.toByteExactOrNull().let { if (it != null) contains(it) else false } @@ -160,6 +165,7 @@ public operator fun ClosedRange.contains(value: Double): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("shortRangeContains") public operator fun ClosedRange.contains(value: Double): Boolean { return value.toShortExactOrNull().let { if (it != null) contains(it) else false } @@ -176,6 +182,7 @@ public operator fun ClosedRange.contains(value: Double): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("intRangeContains") public operator fun ClosedRange.contains(value: Float): Boolean { return value.toIntExactOrNull().let { if (it != null) contains(it) else false } @@ -184,6 +191,7 @@ public operator fun ClosedRange.contains(value: Float): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("longRangeContains") public operator fun ClosedRange.contains(value: Float): Boolean { return value.toLongExactOrNull().let { if (it != null) contains(it) else false } @@ -192,6 +200,7 @@ public operator fun ClosedRange.contains(value: Float): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("byteRangeContains") public operator fun ClosedRange.contains(value: Float): Boolean { return value.toByteExactOrNull().let { if (it != null) contains(it) else false } @@ -200,6 +209,7 @@ public operator fun ClosedRange.contains(value: Float): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("shortRangeContains") public operator fun ClosedRange.contains(value: Float): Boolean { return value.toShortExactOrNull().let { if (it != null) contains(it) else false } @@ -240,6 +250,7 @@ public operator fun ClosedRange.contains(value: Int): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("doubleRangeContains") public operator fun ClosedRange.contains(value: Int): Boolean { return contains(value.toDouble()) @@ -248,6 +259,7 @@ public operator fun ClosedRange.contains(value: Int): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("floatRangeContains") public operator fun ClosedRange.contains(value: Int): Boolean { return contains(value.toFloat()) @@ -280,6 +292,7 @@ public operator fun ClosedRange.contains(value: Long): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("doubleRangeContains") public operator fun ClosedRange.contains(value: Long): Boolean { return contains(value.toDouble()) @@ -288,6 +301,7 @@ public operator fun ClosedRange.contains(value: Long): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("floatRangeContains") public operator fun ClosedRange.contains(value: Long): Boolean { return contains(value.toFloat()) @@ -320,6 +334,7 @@ public operator fun ClosedRange.contains(value: Short): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("doubleRangeContains") public operator fun ClosedRange.contains(value: Short): Boolean { return contains(value.toDouble()) @@ -328,6 +343,7 @@ public operator fun ClosedRange.contains(value: Short): Boolean { /** * Checks if the specified [value] belongs to this range. */ +@Deprecated("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.") @kotlin.jvm.JvmName("floatRangeContains") public operator fun ClosedRange.contains(value: Short): Boolean { return contains(value.toFloat()) diff --git a/libraries/stdlib/test/ranges/RangeTest.kt b/libraries/stdlib/test/ranges/RangeTest.kt index 17d67592a34..2ca24d027ef 100644 --- a/libraries/stdlib/test/ranges/RangeTest.kt +++ b/libraries/stdlib/test/ranges/RangeTest.kt @@ -31,8 +31,10 @@ public class RangeTest { assertTrue(1.toShort() in range) assertTrue(1.toByte() in range) assertTrue(1.toLong() in range) - assertTrue(1.toFloat() in range) - assertTrue(1.toDouble() in range) + run @Suppress("DEPRECATION") { + assertTrue(1.toFloat() in range) + assertTrue(1.toDouble() in range) + } assertFalse(Long.MAX_VALUE in range) @@ -64,8 +66,10 @@ public class RangeTest { assertTrue(1.toShort() in range) assertTrue(1.toInt() in range) assertTrue(1.toLong() in range) - assertTrue(1.toFloat() in range) - assertTrue(1.toDouble() in range) + run @Suppress("DEPRECATION") { + assertTrue(1.toFloat() in range) + assertTrue(1.toDouble() in range) + } assertFalse(Long.MAX_VALUE in range) @@ -98,8 +102,10 @@ public class RangeTest { assertTrue(1.toByte() in range) assertTrue(1.toInt() in range) assertTrue(1.toLong() in range) - assertTrue(1.toFloat() in range) - assertTrue(1.toDouble() in range) + run @Suppress("DEPRECATION") { + assertTrue(1.toFloat() in range) + assertTrue(1.toDouble() in range) + } assertFalse(Long.MAX_VALUE in range) @@ -134,10 +140,13 @@ public class RangeTest { assertTrue(1.toByte() in range) assertTrue(1.toShort() in range) assertTrue(1.toInt() in range) - assertTrue(1.toFloat() in range) - assertTrue(1.toDouble() in range) + run @Suppress("DEPRECATION") { + assertTrue(1.toFloat() in range) + assertTrue(1.toDouble() in range) + + assertFalse(Double.MAX_VALUE in range) + } - assertFalse(Double.MAX_VALUE in range) val openRange = 1L until 10L assertTrue(9L in openRange) @@ -194,10 +203,12 @@ public class RangeTest { assertFalse(range.isEmpty()) - assertTrue(1.toByte() in range) - assertTrue(1.toShort() in range) - assertTrue(1.toInt() in range) - assertTrue(1.toLong() in range) + run @Suppress("DEPRECATION") { + assertTrue(1.toByte() in range) + assertTrue(1.toShort() in range) + assertTrue(1.toInt() in range) + assertTrue(1.toLong() in range) + } assertTrue(1.toFloat() in range) val zeroRange = 0.0..-0.0 @@ -240,10 +251,12 @@ public class RangeTest { assertFalse(range.isEmpty()) - assertTrue(1.toByte() in range) - assertTrue(1.toShort() in range) - assertTrue(1.toInt() in range) - assertTrue(1.toLong() in range) + run @Suppress("DEPRECATION") { + assertTrue(1.toByte() in range) + assertTrue(1.toShort() in range) + assertTrue(1.toInt() in range) + assertTrue(1.toLong() in range) + } assertTrue(1.toDouble() in range) assertFalse(Double.MAX_VALUE in range) diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Ranges.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Ranges.kt index 3f41a901e4f..3479b75741e 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Ranges.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Ranges.kt @@ -160,6 +160,9 @@ object RangeOps : TemplateGroupBase() { signature("contains(value: $itemType)") check(rangeType.isNumeric() == itemType.isNumeric()) { "Required rangeType and itemType both to be numeric or both not, got: $rangeType, $itemType" } + if (rangeType.isIntegral() != itemType.isIntegral()) { + deprecate(Deprecation("This `contains` operation mixing integer and floating point arguments has ambiguous semantics and is going to be removed.", level = DeprecationLevel.WARNING)) + } platformName("${rangeType.name.decapitalize()}RangeContains") returns("Boolean") doc { "Checks if the specified [value] belongs to this range." }