Skip to content

Commit 888ec39

Browse files
committed
Replace tailrec def with a for loop
1 parent 67f1cbf commit 888ec39

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
@@ -1221,7 +1221,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
12211221
rhs: untpd.Tree,
12221222
rhsType: Type,
12231223
prefix: TermName
1224-
)(using Context): untpd.Tree =
1224+
)(using Context): Unit =
12251225
val source = UniqueName.fresh(prefix)
12261226
val d = untpd.ValDef(source, untpd.TypeTree(rhsType), rhs)
12271227
.withSpan(rhs.span)
@@ -1242,20 +1242,15 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
12421242
.withSpan(rhs.span)
12431243

12441244
/** Forms the assignments of the targets in the range [`i`, `targets.length`). */
1245-
@tailrec def loop(i: Int): untpd.Block =
1246-
if (i == targets.length) then
1247-
untpd.Block(statements.toList, untpd.TypedSplice(unitLiteral))
1248-
else targets(i) match {
1245+
for i <- 0 until targets.length do {
1246+
targets(i) match {
12491247
case untpd.Tuple(lhs) =>
12501248
formPairwiseAssignments(statements, lhs, rhsElement(i + 1), sourceTypes(i), source)
1251-
loop(i + 1)
12521249
case lhs =>
12531250
val u = untpd.Assign(lhs, rhsElement(i + 1))
12541251
statements.append(u)
1255-
loop(i + 1)
12561252
}
1257-
1258-
loop(0)
1253+
}
12591254
}
12601255

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

0 commit comments

Comments
 (0)