Skip to content

Commit c58c8c2

Browse files
EugeneFlesselleodersky
authored andcommitted
Do contains runtime operation based on term equality
1 parent 075b7d1 commit c58c8c2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

library/src/scala/Tuple.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,15 @@ object Tuple:
338338
*/
339339
transparent inline def indexOf(y: Any): Int = constValue[IndexOf[X, y.type]]
340340

341-
/** A boolean indicating whether there is an element `y.type` in the type `X` of `x`
342-
*/
343-
transparent inline def contains(y: Any): Boolean = constValue[Contains[X, y.type]]
341+
/** A boolean indicating whether there is an element `y.type` in the type `X` of `x` */
342+
// Note this isn't equivalent to `constValue[Contains[X, y.type]]`
343+
// since it also accepts cases unknown at compiletime.
344+
// Also note it would be unsound to use a type parameter for `y` in the
345+
// type level `Contains`, since it is rightfully not covariant in `Y`.
346+
inline def contains(y: Any): Contains[X, y.type] =
347+
x.productIterator.contains(y).asInstanceOf[Contains[X, y.type]]
348+
349+
// TODO containsType ?
344350

345351
end extension
346352

0 commit comments

Comments
 (0)