Skip to content

Commit c2a6023

Browse files
committed
Replace tailrec def with a for loop
1 parent 91d409a commit c2a6023

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
14401440
rhs: untpd.Tree,
14411441
rhsType: Type,
14421442
prefix: TermName
1443-
)(using Context): untpd.Tree =
1443+
)(using Context): Unit =
14441444
val source = UniqueName.fresh(prefix)
14451445
val d = untpd.ValDef(source, untpd.TypeTree(rhsType), rhs)
14461446
.withSpan(rhs.span)
@@ -1461,20 +1461,15 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
14611461
.withSpan(rhs.span)
14621462

14631463
/** Forms the assignments of the targets in the range [`i`, `targets.length`). */
1464-
@tailrec def loop(i: Int): untpd.Block =
1465-
if (i == targets.length) then
1466-
untpd.Block(statements.toList, untpd.TypedSplice(unitLiteral))
1467-
else targets(i) match {
1464+
for i <- 0 until targets.length do {
1465+
targets(i) match {
14681466
case untpd.Tuple(lhs) =>
14691467
formPairwiseAssignments(statements, lhs, rhsElement(i + 1), sourceTypes(i), source)
1470-
loop(i + 1)
14711468
case lhs =>
14721469
val u = untpd.Assign(lhs, rhsElement(i + 1))
14731470
statements.append(u)
1474-
loop(i + 1)
14751471
}
1476-
1477-
loop(0)
1472+
}
14781473
}
14791474

14801475
def typedBlockStats(stats: List[untpd.Tree])(using Context): (List[tpd.Tree], Context) =

0 commit comments

Comments
 (0)