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:
152
152
def namedTupleElementTypes (derived : Boolean )(using Context ): List [(TermName , Type )] =
153
153
namedTupleElementTypesUpTo(Int .MaxValue , derived)
154
154
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
+
155
166
def isNamedTupleType (using Context ): Boolean = self match
156
167
case defn.NamedTuple (_, _) => true
157
168
case _ => false
Original file line number Diff line number Diff line change @@ -942,7 +942,7 @@ trait Applications extends Compatibility {
942
942
def makeVarArg (n : Int , elemFormal : Type ): Unit = {
943
943
val args = typedArgBuf.takeRight(n).toList
944
944
typedArgBuf.dropRightInPlace(n)
945
- val elemtpt = TypeTree (elemFormal, inferred = true )
945
+ val elemtpt = TypeTree (elemFormal.normalizedTupleType , inferred = true )
946
946
typedArgBuf += seqToRepeated(SeqLiteral (args, elemtpt))
947
947
}
948
948
Original file line number Diff line number Diff line change @@ -847,10 +847,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
847
847
// Otherwise, map combinations of A *: B *: .... EmptyTuple with nesting levels <= 22
848
848
// to the Tuple class of the right arity and select from that one
849
849
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
851
853
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))
854
855
else
855
856
typedSelectWithAdapt(tree, pt, qual)
856
857
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