From the type hierarchy tree in scala
- let a:
Tuple2[Int,Int], I knowTuple2[Int,Int]extends fromProduct2[Int,Int]; - let b:
1 *: 2 *: EmptyTuplehas typeTuple(refined asInt *: Int *: EmptyTuple)
They are different types and don't have any parent relation. The only thing they both have is Product, they both extend from Product.
But I can assign a to b and opposite, why?
In Scala 3, the
Tuple1...Tuple22types are synthetically modified by the compiler to extend the*:types. That is,Tuple2[A, B]is modified to extendA *: B *: EmptyTuple(which extendsTuple).Therefore, you can assign a
Tuple2[Int, Int]to aInt *: Int *: EmptyTuple. Likewise, the reverse is possible because aA *: ... EmptyTuplewill be treated like aTupleNwhenever it can (<= 22 type arguments).