File tree Expand file tree Collapse file tree 5 files changed +20
-4
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 5 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,17 @@ class TypeUtils:
152152 def namedTupleElementTypes (derived : Boolean )(using Context ): List [(TermName , Type )] =
153153 namedTupleElementTypesUpTo(Int .MaxValue , derived)
154154
155+ /** If this is a generic tuple type with arity <= MaxTupleArity, return the
156+ * corresponding TupleN type, otherwise return this.
157+ */
158+ def normalizedTupleType (using Context ): Type =
159+ if self.isGenericTuple then
160+ self.tupleElementTypes match
161+ case Some (elems) if elems.size <= Definitions .MaxTupleArity => defn.tupleType(elems)
162+ case _ => self
163+ else
164+ self
165+
155166 def isNamedTupleType (using Context ): Boolean = self match
156167 case defn.NamedTuple (_, _) => true
157168 case _ => false
Original file line number Diff line number Diff line change @@ -942,7 +942,7 @@ trait Applications extends Compatibility {
942942 def makeVarArg (n : Int , elemFormal : Type ): Unit = {
943943 val args = typedArgBuf.takeRight(n).toList
944944 typedArgBuf.dropRightInPlace(n)
945- val elemtpt = TypeTree (elemFormal, inferred = true )
945+ val elemtpt = TypeTree (elemFormal.normalizedTupleType , inferred = true )
946946 typedArgBuf += seqToRepeated(SeqLiteral (args, elemtpt))
947947 }
948948
Original file line number Diff line number Diff line change @@ -847,10 +847,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
847847 // Otherwise, map combinations of A *: B *: .... EmptyTuple with nesting levels <= 22
848848 // to the Tuple class of the right arity and select from that one
849849 def trySmallGenericTuple (qual : Tree , withCast : Boolean ) =
850- if qual.tpe.isSmallGenericTuple then
850+ val tp = qual.tpe.widenTermRefExpr
851+ val tpNormalized = tp.normalizedTupleType
852+ if tp ne tpNormalized then
851853 if withCast then
852- val elems = qual.tpe.widenTermRefExpr.tupleElementTypes.getOrElse(Nil )
853- typedSelectWithAdapt(tree, pt, qual.cast(defn.tupleType(elems)))
854+ typedSelectWithAdapt(tree, pt, qual.cast(tpNormalized))
854855 else
855856 typedSelectWithAdapt(tree, pt, qual)
856857 else EmptyTree
Original file line number Diff line number Diff line change 1+ @ main def Test : Unit =
2+ val a : Array [(Int , String )] = Array [Int *: String *: EmptyTuple ]()
Original file line number Diff line number Diff line change 1+ @ main def Test : Unit =
2+ val a : Array [(Int , String )] = Array [Int *: String *: EmptyTuple ]((1 , " hello" ))
You can’t perform that action at this time.
0 commit comments