@@ -51,31 +51,34 @@ object TypeUtils {
5151
5252 /** The arity of this tuple type, which can be made up of EmptyTuple, TupleX and `*:` pairs,
5353 * 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.
5456 */
55- def tupleArity (using Context ): Int = self match {
57+ def tupleArity (underErasure : Boolean )( using Context ): Int = self match
5658 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
6361 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 )
6670
6771 /** 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
6973 case AppliedType (tycon, hd :: tl :: Nil ) if tycon.isRef(defn.PairClass ) =>
7074 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" )
7982
8083 /** The `*:` equivalent of an instance of a Tuple class */
8184 def toNestedPairs (using Context ): Type =
0 commit comments