Skip to content

Commit 14d5635

Browse files
committed
Rewrite code for flexible repeated types
1 parent 68085fc commit 14d5635

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

compiler/src/dotty/tools/dotc/core/TypeApplications.scala

+1
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ class TypeApplications(val self: Type) extends AnyVal {
541541
*/
542542
final def argInfos(using Context): List[Type] = self.stripped match
543543
case AppliedType(tycon, args) => args
544+
case tp: FlexibleType => tp.underlying.argInfos
544545
case _ => Nil
545546

546547
/** If this is an encoding of a function type, return its arguments, otherwise return Nil.

compiler/src/dotty/tools/dotc/typer/Applications.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -644,15 +644,14 @@ trait Applications extends Compatibility {
644644
missingArg(n)
645645
}
646646

647-
val formal1 = formal.stripFlexible
648-
if (formal1.isRepeatedParam)
647+
if formal.isRepeatedParam then
649648
args match {
650649
case arg :: Nil if isVarArg(arg) =>
651650
addTyped(arg)
652651
case (arg @ Typed(Literal(Constant(null)), _)) :: Nil if ctx.isAfterTyper =>
653652
addTyped(arg)
654653
case _ =>
655-
val elemFormal = formal1.widenExpr.argTypesLo.head
654+
val elemFormal = formal.widenExpr.argTypesLo.head
656655
val typedArgs =
657656
harmonic(harmonizeArgs, elemFormal) {
658657
args.map { arg =>

compiler/src/dotty/tools/dotc/typer/Typer.scala

+13-9
Original file line numberDiff line numberDiff line change
@@ -981,19 +981,23 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
981981
}
982982

983983
if (untpd.isWildcardStarArg(tree)) {
984+
985+
def fromRepeated(pt: Type): Type = pt match
986+
case pt: FlexibleType =>
987+
pt.derivedFlexibleType(fromRepeated(pt.hi))
988+
case _ =>
989+
if ctx.mode.isQuotedPattern then
990+
// FIXME(#8680): Quoted patterns do not support Array repeated arguments
991+
pt.translateFromRepeated(toArray = false, translateWildcard = true)
992+
else
993+
pt.translateFromRepeated(toArray = false, translateWildcard = true)
994+
| pt.translateFromRepeated(toArray = true, translateWildcard = true)
995+
984996
def typedWildcardStarArgExpr = {
985997
// A sequence argument `xs: _*` can be either a `Seq[T]` or an `Array[_ <: T]`,
986998
// irrespective of whether the method we're calling is a Java or Scala method,
987999
// so the expected type is the union `Seq[T] | Array[_ <: T]`.
988-
val pt1 = pt.stripFlexible
989-
val ptArg0 =
990-
// FIXME(#8680): Quoted patterns do not support Array repeated arguments
991-
if ctx.mode.isQuotedPattern then
992-
pt1.translateFromRepeated(toArray = false, translateWildcard = true)
993-
else
994-
pt1.translateFromRepeated(toArray = false, translateWildcard = true)
995-
| pt1.translateFromRepeated(toArray = true, translateWildcard = true)
996-
val ptArg = if pt1 eq pt then ptArg0 else FlexibleType(ptArg0)
1000+
val ptArg = fromRepeated(pt)
9971001
val expr0 = typedExpr(tree.expr, ptArg)
9981002
val expr1 = if ctx.explicitNulls && (!ctx.mode.is(Mode.Pattern)) then
9991003
if expr0.tpe.isNullType then

0 commit comments

Comments
 (0)