File tree 6 files changed +16
-16
lines changed
compiler/src/dotty/tools/dotc
6 files changed +16
-16
lines changed Original file line number Diff line number Diff line change @@ -1352,7 +1352,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
1352
1352
* Used to make arguments for methods that accept varargs.
1353
1353
*/
1354
1354
def repeated (trees : List [Tree ], tpt : Tree )(using Context ): Tree =
1355
- ctx.typeAssigner.arrayToRepeated (JavaSeqLiteral (trees, tpt))
1355
+ ctx.typeAssigner.toRepeated (JavaSeqLiteral (trees, tpt))
1356
1356
1357
1357
/** Create a tree representing a list containing all
1358
1358
* the elements of the argument list. A "list of tree to
Original file line number Diff line number Diff line change @@ -402,6 +402,14 @@ class TypeApplications(val self: Type) extends AnyVal {
402
402
translateParameterized(defn.RepeatedParamClass , seqClass, wildcardArg = toArray)
403
403
else self
404
404
405
+ /** Translate a `Seq[T]` or `Array[T]` into a `*T`, keep other types as is. */
406
+ def translateToRepeated (using Context ): Type =
407
+ val from = self.widenDealias.classSymbol
408
+ if (from eq defn.SeqClass ) || (from eq defn.ArrayClass )
409
+ translateParameterized(from.asClass, defn.RepeatedParamClass )
410
+ else
411
+ self
412
+
405
413
/** If this is an encoding of a (partially) applied type, return its arguments,
406
414
* otherwise return Nil.
407
415
* Existential types in arguments are returned as TypeBounds instances.
Original file line number Diff line number Diff line change @@ -421,7 +421,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
421
421
val elem =
422
422
param.select(defn.Product_productElement ).appliedTo(Literal (Constant (idx)))
423
423
.ensureConforms(formal.translateFromRepeated(toArray = false ))
424
- if (formal.isRepeatedParam) ctx.typer.seqToRepeated (elem) else elem
424
+ if (formal.isRepeatedParam) ctx.typeAssigner.toRepeated (elem) else elem
425
425
}
426
426
New (classRef, elems)
427
427
}
Original file line number Diff line number Diff line change @@ -697,7 +697,7 @@ trait Applications extends Compatibility {
697
697
val args = typedArgBuf.takeRight(n).toList
698
698
typedArgBuf.trimEnd(n)
699
699
val elemtpt = TypeTree (elemFormal)
700
- typedArgBuf += seqToRepeated (SeqLiteral (args, elemtpt))
700
+ typedArgBuf += ctx.typeAssigner.toRepeated (SeqLiteral (args, elemtpt))
701
701
}
702
702
703
703
def harmonizeArgs (args : List [TypedArg ]): List [Tree ] = harmonize(args)
Original file line number Diff line number Diff line change @@ -165,12 +165,8 @@ trait TypeAssigner {
165
165
then checkNoPrivateLeaks(sym)
166
166
else sym.info
167
167
168
- private def toRepeated (tree : Tree , from : ClassSymbol )(using Context ): Tree =
169
- Typed (tree, TypeTree (tree.tpe.widen.translateParameterized(from, defn.RepeatedParamClass )))
170
-
171
- def seqToRepeated (tree : Tree )(using Context ): Tree = toRepeated(tree, defn.SeqClass )
172
-
173
- def arrayToRepeated (tree : Tree )(using Context ): Tree = toRepeated(tree, defn.ArrayClass )
168
+ def toRepeated (tree : Tree )(using Context ): Tree =
169
+ Typed (tree, TypeTree (tree.tpe.translateToRepeated))
174
170
175
171
/** A denotation exists really if it exists and does not point to a stale symbol. */
176
172
final def reallyExists (denot : Denotation )(using Context ): Boolean = try
Original file line number Diff line number Diff line change @@ -733,13 +733,9 @@ class Typer extends Namer
733
733
// FIXME(#8680): Quoted patterns do not support Array repeated arguments
734
734
if (ctx.mode.is(Mode .QuotedPattern )) pt.translateFromRepeated(toArray = false )
735
735
else pt.translateFromRepeated(toArray = false ) | pt.translateFromRepeated(toArray = true )
736
- val tpdExpr = typedExpr(tree.expr, ptArg)
737
- tpdExpr.tpe.widenDealias match {
738
- case defn.ArrayOf (_) =>
739
- arrayToRepeated(tpdExpr)
740
- case _ =>
741
- seqToRepeated(tpdExpr)
742
- }
736
+ val expr1 = typedExpr(tree.expr, ptArg)
737
+ val tpt1 = TypeTree (expr1.tpe.translateToRepeated).withSpan(tree.tpt.span)
738
+ assignType(cpy.Typed (tree)(expr1, tpt1), tpt1)
743
739
}
744
740
cases(
745
741
ifPat = ascription(TypeTree (defn.RepeatedParamType .appliedTo(pt)), isWildcard = true ),
You can’t perform that action at this time.
0 commit comments