Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/TailRec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ class TailRec extends MiniPhase {
case prefix: This if prefix.symbol == enclosingClass =>
// Avoid assigning `this = this`
assignParamPairs
case prefix if prefix.symbol.is(Module) && prefix.symbol.moduleClass == enclosingClass =>
case prefix
if prefix.symbol.is(Module)
&& prefix.symbol.moduleClass == enclosingClass
&& isPurePath(prefix) =>
// Avoid assigning `this = MyObject`
assignParamPairs
case _ =>
Expand Down
22 changes: 22 additions & 0 deletions tests/run/i23444.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

import annotation.*

class Path(action: () => Unit, parent: Option[Path]):
object O:
@tailrec
def apply(): Unit =
action()

parent match
case Some(p) =>
p.O.apply()
case None =>

@main def Test: Unit =
var counter = 0
val fun = () => {
counter += 1
if counter > 2 then throw AssertionError("bad loop")
}
val path = Path(fun, Some(Path(fun, None)))
path.O()
Loading