Skip to content

Commit 2395004

Browse files
committed
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
1 parent ef278ea commit 2395004

File tree

5 files changed

+129
-0
lines changed

5 files changed

+129
-0
lines changed

libraries/stdlib/common/src/generated/_Arrays.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5617,6 +5617,9 @@ public expect fun CharArray.asList(): List<Char>
56175617
*
56185618
* If two corresponding elements are nested arrays, they are also compared deeply.
56195619
* If any of arrays contains itself on any nesting level the behavior is undefined.
5620+
*
5621+
* The elements of other types are compared for equality with the [equals][Any.equals] function.
5622+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
56205623
*/
56215624
@SinceKotlin("1.1")
56225625
public expect infix fun <T> Array<out T>.contentDeepEquals(other: Array<out T>): Boolean
@@ -5645,62 +5648,89 @@ public expect fun <T> Array<out T>.contentDeepToString(): String
56455648
/**
56465649
* Returns `true` if the two specified arrays are *structurally* equal to one another,
56475650
* i.e. contain the same number of the same elements in the same order.
5651+
*
5652+
* The elements are compared for equality with the [equals][Any.equals] function.
5653+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
56485654
*/
56495655
@SinceKotlin("1.1")
56505656
public expect infix fun <T> Array<out T>.contentEquals(other: Array<out T>): Boolean
56515657

56525658
/**
56535659
* Returns `true` if the two specified arrays are *structurally* equal to one another,
56545660
* i.e. contain the same number of the same elements in the same order.
5661+
*
5662+
* The elements are compared for equality with the [equals][Any.equals] function.
5663+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
56555664
*/
56565665
@SinceKotlin("1.1")
56575666
public expect infix fun ByteArray.contentEquals(other: ByteArray): Boolean
56585667

56595668
/**
56605669
* Returns `true` if the two specified arrays are *structurally* equal to one another,
56615670
* i.e. contain the same number of the same elements in the same order.
5671+
*
5672+
* The elements are compared for equality with the [equals][Any.equals] function.
5673+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
56625674
*/
56635675
@SinceKotlin("1.1")
56645676
public expect infix fun ShortArray.contentEquals(other: ShortArray): Boolean
56655677

56665678
/**
56675679
* Returns `true` if the two specified arrays are *structurally* equal to one another,
56685680
* i.e. contain the same number of the same elements in the same order.
5681+
*
5682+
* The elements are compared for equality with the [equals][Any.equals] function.
5683+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
56695684
*/
56705685
@SinceKotlin("1.1")
56715686
public expect infix fun IntArray.contentEquals(other: IntArray): Boolean
56725687

56735688
/**
56745689
* Returns `true` if the two specified arrays are *structurally* equal to one another,
56755690
* i.e. contain the same number of the same elements in the same order.
5691+
*
5692+
* The elements are compared for equality with the [equals][Any.equals] function.
5693+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
56765694
*/
56775695
@SinceKotlin("1.1")
56785696
public expect infix fun LongArray.contentEquals(other: LongArray): Boolean
56795697

56805698
/**
56815699
* Returns `true` if the two specified arrays are *structurally* equal to one another,
56825700
* i.e. contain the same number of the same elements in the same order.
5701+
*
5702+
* The elements are compared for equality with the [equals][Any.equals] function.
5703+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
56835704
*/
56845705
@SinceKotlin("1.1")
56855706
public expect infix fun FloatArray.contentEquals(other: FloatArray): Boolean
56865707

56875708
/**
56885709
* Returns `true` if the two specified arrays are *structurally* equal to one another,
56895710
* i.e. contain the same number of the same elements in the same order.
5711+
*
5712+
* The elements are compared for equality with the [equals][Any.equals] function.
5713+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
56905714
*/
56915715
@SinceKotlin("1.1")
56925716
public expect infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean
56935717

56945718
/**
56955719
* Returns `true` if the two specified arrays are *structurally* equal to one another,
56965720
* i.e. contain the same number of the same elements in the same order.
5721+
*
5722+
* The elements are compared for equality with the [equals][Any.equals] function.
5723+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
56975724
*/
56985725
@SinceKotlin("1.1")
56995726
public expect infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean
57005727

57015728
/**
57025729
* Returns `true` if the two specified arrays are *structurally* equal to one another,
57035730
* i.e. contain the same number of the same elements in the same order.
5731+
*
5732+
* The elements are compared for equality with the [equals][Any.equals] function.
5733+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
57045734
*/
57055735
@SinceKotlin("1.1")
57065736
public expect infix fun CharArray.contentEquals(other: CharArray): Boolean

libraries/stdlib/js/irRuntime/generated/_ArraysJs.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public actual fun CharArray.asList(): List<Char> {
9797
*
9898
* If two corresponding elements are nested arrays, they are also compared deeply.
9999
* If any of arrays contains itself on any nesting level the behavior is undefined.
100+
*
101+
* The elements of other types are compared for equality with the [equals][Any.equals] function.
102+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
100103
*/
101104
@SinceKotlin("1.1")
102105
public actual infix fun <T> Array<out T>.contentDeepEquals(other: Array<out T>): Boolean {
@@ -131,6 +134,9 @@ public actual fun <T> Array<out T>.contentDeepToString(): String {
131134
/**
132135
* Returns `true` if the two specified arrays are *structurally* equal to one another,
133136
* i.e. contain the same number of the same elements in the same order.
137+
*
138+
* The elements are compared for equality with the [equals][Any.equals] function.
139+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
134140
*/
135141
@SinceKotlin("1.1")
136142
public actual infix fun <T> Array<out T>.contentEquals(other: Array<out T>): Boolean {
@@ -140,6 +146,9 @@ public actual infix fun <T> Array<out T>.contentEquals(other: Array<out T>): Boo
140146
/**
141147
* Returns `true` if the two specified arrays are *structurally* equal to one another,
142148
* i.e. contain the same number of the same elements in the same order.
149+
*
150+
* The elements are compared for equality with the [equals][Any.equals] function.
151+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
143152
*/
144153
@SinceKotlin("1.1")
145154
public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean {
@@ -149,6 +158,9 @@ public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean {
149158
/**
150159
* Returns `true` if the two specified arrays are *structurally* equal to one another,
151160
* i.e. contain the same number of the same elements in the same order.
161+
*
162+
* The elements are compared for equality with the [equals][Any.equals] function.
163+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
152164
*/
153165
@SinceKotlin("1.1")
154166
public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean {
@@ -158,6 +170,9 @@ public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean {
158170
/**
159171
* Returns `true` if the two specified arrays are *structurally* equal to one another,
160172
* i.e. contain the same number of the same elements in the same order.
173+
*
174+
* The elements are compared for equality with the [equals][Any.equals] function.
175+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
161176
*/
162177
@SinceKotlin("1.1")
163178
public actual infix fun IntArray.contentEquals(other: IntArray): Boolean {
@@ -167,6 +182,9 @@ public actual infix fun IntArray.contentEquals(other: IntArray): Boolean {
167182
/**
168183
* Returns `true` if the two specified arrays are *structurally* equal to one another,
169184
* i.e. contain the same number of the same elements in the same order.
185+
*
186+
* The elements are compared for equality with the [equals][Any.equals] function.
187+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
170188
*/
171189
@SinceKotlin("1.1")
172190
public actual infix fun LongArray.contentEquals(other: LongArray): Boolean {
@@ -176,6 +194,9 @@ public actual infix fun LongArray.contentEquals(other: LongArray): Boolean {
176194
/**
177195
* Returns `true` if the two specified arrays are *structurally* equal to one another,
178196
* i.e. contain the same number of the same elements in the same order.
197+
*
198+
* The elements are compared for equality with the [equals][Any.equals] function.
199+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
179200
*/
180201
@SinceKotlin("1.1")
181202
public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean {
@@ -185,6 +206,9 @@ public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean {
185206
/**
186207
* Returns `true` if the two specified arrays are *structurally* equal to one another,
187208
* i.e. contain the same number of the same elements in the same order.
209+
*
210+
* The elements are compared for equality with the [equals][Any.equals] function.
211+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
188212
*/
189213
@SinceKotlin("1.1")
190214
public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean {
@@ -194,6 +218,9 @@ public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean {
194218
/**
195219
* Returns `true` if the two specified arrays are *structurally* equal to one another,
196220
* i.e. contain the same number of the same elements in the same order.
221+
*
222+
* The elements are compared for equality with the [equals][Any.equals] function.
223+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
197224
*/
198225
@SinceKotlin("1.1")
199226
public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean {
@@ -203,6 +230,9 @@ public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean
203230
/**
204231
* Returns `true` if the two specified arrays are *structurally* equal to one another,
205232
* i.e. contain the same number of the same elements in the same order.
233+
*
234+
* The elements are compared for equality with the [equals][Any.equals] function.
235+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
206236
*/
207237
@SinceKotlin("1.1")
208238
public actual infix fun CharArray.contentEquals(other: CharArray): Boolean {

libraries/stdlib/js/src/generated/_ArraysJs.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public actual fun CharArray.asList(): List<Char> {
9797
*
9898
* If two corresponding elements are nested arrays, they are also compared deeply.
9999
* If any of arrays contains itself on any nesting level the behavior is undefined.
100+
*
101+
* The elements of other types are compared for equality with the [equals][Any.equals] function.
102+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
100103
*/
101104
@SinceKotlin("1.1")
102105
@library("arrayDeepEquals")
@@ -134,6 +137,9 @@ public actual fun <T> Array<out T>.contentDeepToString(): String {
134137
/**
135138
* Returns `true` if the two specified arrays are *structurally* equal to one another,
136139
* i.e. contain the same number of the same elements in the same order.
140+
*
141+
* The elements are compared for equality with the [equals][Any.equals] function.
142+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
137143
*/
138144
@SinceKotlin("1.1")
139145
@library("arrayEquals")
@@ -144,6 +150,9 @@ public actual infix fun <T> Array<out T>.contentEquals(other: Array<out T>): Boo
144150
/**
145151
* Returns `true` if the two specified arrays are *structurally* equal to one another,
146152
* i.e. contain the same number of the same elements in the same order.
153+
*
154+
* The elements are compared for equality with the [equals][Any.equals] function.
155+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
147156
*/
148157
@SinceKotlin("1.1")
149158
@library("arrayEquals")
@@ -154,6 +163,9 @@ public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean {
154163
/**
155164
* Returns `true` if the two specified arrays are *structurally* equal to one another,
156165
* i.e. contain the same number of the same elements in the same order.
166+
*
167+
* The elements are compared for equality with the [equals][Any.equals] function.
168+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
157169
*/
158170
@SinceKotlin("1.1")
159171
@library("arrayEquals")
@@ -164,6 +176,9 @@ public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean {
164176
/**
165177
* Returns `true` if the two specified arrays are *structurally* equal to one another,
166178
* i.e. contain the same number of the same elements in the same order.
179+
*
180+
* The elements are compared for equality with the [equals][Any.equals] function.
181+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
167182
*/
168183
@SinceKotlin("1.1")
169184
@library("arrayEquals")
@@ -174,6 +189,9 @@ public actual infix fun IntArray.contentEquals(other: IntArray): Boolean {
174189
/**
175190
* Returns `true` if the two specified arrays are *structurally* equal to one another,
176191
* i.e. contain the same number of the same elements in the same order.
192+
*
193+
* The elements are compared for equality with the [equals][Any.equals] function.
194+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
177195
*/
178196
@SinceKotlin("1.1")
179197
@library("arrayEquals")
@@ -184,6 +202,9 @@ public actual infix fun LongArray.contentEquals(other: LongArray): Boolean {
184202
/**
185203
* Returns `true` if the two specified arrays are *structurally* equal to one another,
186204
* i.e. contain the same number of the same elements in the same order.
205+
*
206+
* The elements are compared for equality with the [equals][Any.equals] function.
207+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
187208
*/
188209
@SinceKotlin("1.1")
189210
@library("arrayEquals")
@@ -194,6 +215,9 @@ public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean {
194215
/**
195216
* Returns `true` if the two specified arrays are *structurally* equal to one another,
196217
* i.e. contain the same number of the same elements in the same order.
218+
*
219+
* The elements are compared for equality with the [equals][Any.equals] function.
220+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
197221
*/
198222
@SinceKotlin("1.1")
199223
@library("arrayEquals")
@@ -204,6 +228,9 @@ public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean {
204228
/**
205229
* Returns `true` if the two specified arrays are *structurally* equal to one another,
206230
* i.e. contain the same number of the same elements in the same order.
231+
*
232+
* The elements are compared for equality with the [equals][Any.equals] function.
233+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
207234
*/
208235
@SinceKotlin("1.1")
209236
@library("arrayEquals")
@@ -214,6 +241,9 @@ public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean
214241
/**
215242
* Returns `true` if the two specified arrays are *structurally* equal to one another,
216243
* i.e. contain the same number of the same elements in the same order.
244+
*
245+
* The elements are compared for equality with the [equals][Any.equals] function.
246+
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
217247
*/
218248
@SinceKotlin("1.1")
219249
@library("arrayEquals")

0 commit comments

Comments
 (0)