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