From 23950042f6f1bcf6849f442dec413a85de9eb96b Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Fri, 7 Dec 2018 20:41:30 +0300 Subject: [PATCH] Clarify how elements of arrays are compared by contentEquals function Add clarification only for the particular group of overloads including arrays of object and floating point numbers. #KT-22942 Fixed --- .../stdlib/common/src/generated/_Arrays.kt | 30 +++++++++++++++++++ .../js/irRuntime/generated/_ArraysJs.kt | 30 +++++++++++++++++++ .../stdlib/js/src/generated/_ArraysJs.kt | 30 +++++++++++++++++++ .../stdlib/jvm/src/generated/_ArraysJvm.kt | 30 +++++++++++++++++++ .../kotlin-stdlib-gen/src/templates/Arrays.kt | 9 ++++++ 5 files changed, 129 insertions(+) diff --git a/libraries/stdlib/common/src/generated/_Arrays.kt b/libraries/stdlib/common/src/generated/_Arrays.kt index e80b824e4fe..59127d8e20c 100644 --- a/libraries/stdlib/common/src/generated/_Arrays.kt +++ b/libraries/stdlib/common/src/generated/_Arrays.kt @@ -5617,6 +5617,9 @@ public expect fun CharArray.asList(): List * * If two corresponding elements are nested arrays, they are also compared deeply. * If any of arrays contains itself on any nesting level the behavior is undefined. + * + * The elements of other types are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public expect infix fun Array.contentDeepEquals(other: Array): Boolean @@ -5645,6 +5648,9 @@ public expect fun Array.contentDeepToString(): String /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public expect infix fun Array.contentEquals(other: Array): Boolean @@ -5652,6 +5658,9 @@ public expect infix fun Array.contentEquals(other: Array): Boo /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public expect infix fun ByteArray.contentEquals(other: ByteArray): Boolean @@ -5659,6 +5668,9 @@ public expect infix fun ByteArray.contentEquals(other: ByteArray): Boolean /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public expect infix fun ShortArray.contentEquals(other: ShortArray): Boolean @@ -5666,6 +5678,9 @@ public expect infix fun ShortArray.contentEquals(other: ShortArray): Boolean /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public expect infix fun IntArray.contentEquals(other: IntArray): Boolean @@ -5673,6 +5688,9 @@ public expect infix fun IntArray.contentEquals(other: IntArray): Boolean /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public expect infix fun LongArray.contentEquals(other: LongArray): Boolean @@ -5680,6 +5698,9 @@ public expect infix fun LongArray.contentEquals(other: LongArray): Boolean /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public expect infix fun FloatArray.contentEquals(other: FloatArray): Boolean @@ -5687,6 +5708,9 @@ public expect infix fun FloatArray.contentEquals(other: FloatArray): Boolean /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public expect infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean @@ -5694,6 +5718,9 @@ public expect infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public expect infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean @@ -5701,6 +5728,9 @@ public expect infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public expect infix fun CharArray.contentEquals(other: CharArray): Boolean diff --git a/libraries/stdlib/js/irRuntime/generated/_ArraysJs.kt b/libraries/stdlib/js/irRuntime/generated/_ArraysJs.kt index 782d755f734..4af1303e786 100644 --- a/libraries/stdlib/js/irRuntime/generated/_ArraysJs.kt +++ b/libraries/stdlib/js/irRuntime/generated/_ArraysJs.kt @@ -97,6 +97,9 @@ public actual fun CharArray.asList(): List { * * If two corresponding elements are nested arrays, they are also compared deeply. * If any of arrays contains itself on any nesting level the behavior is undefined. + * + * The elements of other types are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun Array.contentDeepEquals(other: Array): Boolean { @@ -131,6 +134,9 @@ public actual fun Array.contentDeepToString(): String { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun Array.contentEquals(other: Array): Boolean { @@ -140,6 +146,9 @@ public actual infix fun Array.contentEquals(other: Array): Boo /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean { @@ -149,6 +158,9 @@ public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean { @@ -158,6 +170,9 @@ public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun IntArray.contentEquals(other: IntArray): Boolean { @@ -167,6 +182,9 @@ public actual infix fun IntArray.contentEquals(other: IntArray): Boolean { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun LongArray.contentEquals(other: LongArray): Boolean { @@ -176,6 +194,9 @@ public actual infix fun LongArray.contentEquals(other: LongArray): Boolean { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean { @@ -185,6 +206,9 @@ public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean { @@ -194,6 +218,9 @@ public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean { @@ -203,6 +230,9 @@ public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun CharArray.contentEquals(other: CharArray): Boolean { diff --git a/libraries/stdlib/js/src/generated/_ArraysJs.kt b/libraries/stdlib/js/src/generated/_ArraysJs.kt index a34e70d0571..e2144d233d5 100644 --- a/libraries/stdlib/js/src/generated/_ArraysJs.kt +++ b/libraries/stdlib/js/src/generated/_ArraysJs.kt @@ -97,6 +97,9 @@ public actual fun CharArray.asList(): List { * * If two corresponding elements are nested arrays, they are also compared deeply. * If any of arrays contains itself on any nesting level the behavior is undefined. + * + * The elements of other types are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") @library("arrayDeepEquals") @@ -134,6 +137,9 @@ public actual fun Array.contentDeepToString(): String { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") @library("arrayEquals") @@ -144,6 +150,9 @@ public actual infix fun Array.contentEquals(other: Array): Boo /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") @library("arrayEquals") @@ -154,6 +163,9 @@ public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") @library("arrayEquals") @@ -164,6 +176,9 @@ public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") @library("arrayEquals") @@ -174,6 +189,9 @@ public actual infix fun IntArray.contentEquals(other: IntArray): Boolean { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") @library("arrayEquals") @@ -184,6 +202,9 @@ public actual infix fun LongArray.contentEquals(other: LongArray): Boolean { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") @library("arrayEquals") @@ -194,6 +215,9 @@ public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") @library("arrayEquals") @@ -204,6 +228,9 @@ public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") @library("arrayEquals") @@ -214,6 +241,9 @@ public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") @library("arrayEquals") diff --git a/libraries/stdlib/jvm/src/generated/_ArraysJvm.kt b/libraries/stdlib/jvm/src/generated/_ArraysJvm.kt index 97a00ceb266..770b6a33d80 100644 --- a/libraries/stdlib/jvm/src/generated/_ArraysJvm.kt +++ b/libraries/stdlib/jvm/src/generated/_ArraysJvm.kt @@ -290,6 +290,9 @@ public fun CharArray.binarySearch(element: Char, fromIndex: Int = 0, toIndex: In * * If two corresponding elements are nested arrays, they are also compared deeply. * If any of arrays contains itself on any nesting level the behavior is undefined. + * + * The elements of other types are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") @JvmName("contentDeepEqualsInline") @@ -339,6 +342,9 @@ public actual inline fun Array.contentDeepToString(): String { /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. + * + * The elements are compared for equality with the [equals][Any.equals] function. + * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly @@ -349,6 +355,9 @@ public actual inline infix fun Array.contentEquals(other: Array