Skip to content

Commit 9047ac3

Browse files
EugeneFlesselleodersky
authored andcommitted
Fix def indexOf to return the size instead of -1
1 parent 03509b8 commit 9047ac3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

library/src/scala/Tuple.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,14 @@ object Tuple:
350350
// Also note it would be unsound to use a type parameter for `y` in the type level
351351
// operations, since they are rightfully not covariant in their second parameter.
352352

353-
/** The index (starting at 0) of the first occurrence of y.type in the type `X` of `x`
354-
* or Size[X] if no such element exists.
353+
/** The index (starting at 0) of the first occurrence of `y` in `x`
354+
* or its size if no such element exists.
355355
*/
356356
inline def indexOf(y: Any): IndexOf[X, y.type] =
357-
x.productIterator.indexOf(y).asInstanceOf[IndexOf[X, y.type]]
357+
val i = x.productIterator.indexOf(y)
358+
(if i >= 0 then i else x.size).asInstanceOf[IndexOf[X, y.type]]
358359

359-
/** A boolean indicating whether there is an element `y.type` in the type `X` of `x` */
360+
/** A boolean indicating whether `x` contains the element `y` */
360361
inline def contains(y: Any): Contains[X, y.type] =
361362
x.productIterator.contains(y).asInstanceOf[Contains[X, y.type]]
362363

0 commit comments

Comments
 (0)