@@ -51,31 +51,34 @@ object TypeUtils {
51
51
52
52
/** The arity of this tuple type, which can be made up of EmptyTuple, TupleX and `*:` pairs,
53
53
* or -1 if this is not a tuple type.
54
+ * We treat the arity under erasure specially to erase `T *: EmptyTuple` to `Product`
55
+ * but `T *: EmptyTuple.type` to `Tuple1` for binary compatibility.
54
56
*/
55
- def tupleArity (using Context ): Int = self match {
57
+ def tupleArity (underErasure : Boolean )( using Context ): Int = self match
56
58
case AppliedType (tycon, _ :: tl :: Nil ) if tycon.isRef(defn.PairClass ) =>
57
- val arity = tl.tupleArity
58
- if (arity < 0 ) arity else arity + 1
59
- case self : SingletonType =>
60
- if self.termSymbol == defn.EmptyTupleModule then 0 else - 1
61
- case self if defn.isTupleClass(self.classSymbol) =>
62
- self.dealias.argInfos.length
59
+ val arity = tl.tupleArity(underErasure)
60
+ if arity < 0 then arity else arity + 1
63
61
case _ =>
64
- - 1
65
- }
62
+ if self.termSymbol == defn.EmptyTupleModule then
63
+ if ! underErasure || self.isInstanceOf [SingletonType ] then 0 else - 1
64
+ else if defn.isTupleClass(self.classSymbol) then
65
+ self.widenTermRefExpr.dealias.argInfos.length
66
+ else
67
+ - 1
68
+
69
+ inline def tupleArity (using Context ): Int = tupleArity(underErasure = false )
66
70
67
71
/** The element types of this tuple type, which can be made up of EmptyTuple, TupleX and `*:` pairs */
68
- def tupleElementTypes (using Context ): List [Type ] = self match {
72
+ def tupleElementTypes (using Context ): List [Type ] = self match
69
73
case AppliedType (tycon, hd :: tl :: Nil ) if tycon.isRef(defn.PairClass ) =>
70
74
hd :: tl.tupleElementTypes
71
- case self : SingletonType =>
72
- assert(self.termSymbol == defn.EmptyTupleModule , " not a tuple" )
73
- Nil
74
- case self if defn.isTupleClass(self.classSymbol) =>
75
- self.dealias.argInfos
76
- case _ =>
77
- throw new AssertionError (" not a tuple" )
78
- }
75
+ case _ =>
76
+ if self.termSymbol == defn.EmptyTupleModule then
77
+ Nil
78
+ else if defn.isTupleClass(self.classSymbol) then
79
+ self.widenTermRefExpr.dealias.argInfos
80
+ else
81
+ throw new AssertionError (" not a tuple" )
79
82
80
83
/** The `*:` equivalent of an instance of a Tuple class */
81
84
def toNestedPairs (using Context ): Type =
0 commit comments