Skip to content

Commit eb44709

Browse files
authored
Merge pull request #514 from scala/backport-lts-3.3-23491
Backport "Check path of module prefix for tailrec" to 3.3 LTS
2 parents f7a5aca + 4d235ad commit eb44709

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

compiler/src/dotty/tools/dotc/transform/TailRec.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,10 @@ class TailRec extends MiniPhase {
344344
case prefix: This if prefix.symbol == enclosingClass =>
345345
// Avoid assigning `this = this`
346346
assignParamPairs
347-
case prefix if prefix.symbol.is(Module) && prefix.symbol.moduleClass == enclosingClass =>
347+
case prefix
348+
if prefix.symbol.is(Module)
349+
&& prefix.symbol.moduleClass == enclosingClass
350+
&& isPurePath(prefix) =>
348351
// Avoid assigning `this = MyObject`
349352
assignParamPairs
350353
case _ =>

tests/run/i23444.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
import annotation.*
3+
4+
class Path(action: () => Unit, parent: Option[Path]):
5+
object O:
6+
@tailrec
7+
def apply(): Unit =
8+
action()
9+
10+
parent match
11+
case Some(p) =>
12+
p.O.apply()
13+
case None =>
14+
15+
@main def Test: Unit =
16+
var counter = 0
17+
val fun = () => {
18+
counter += 1
19+
if counter > 2 then throw AssertionError("bad loop")
20+
}
21+
val path = Path(fun, Some(Path(fun, None)))
22+
path.O()

0 commit comments

Comments
 (0)