File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -194,7 +194,8 @@ class TailRec extends MiniPhase {
194194 def isInfiniteRecCall (tree : Tree ): Boolean = {
195195 def tailArgOrPureExpr (stat : Tree ): Boolean = stat match {
196196 case stat : ValDef if stat.name.is(TailTempName ) || ! stat.symbol.is(Mutable ) => tailArgOrPureExpr(stat.rhs)
197- case Assign (lhs : Ident , rhs) if lhs.symbol.name.is(TailLocalName ) => tailArgOrPureExpr(rhs)
197+ case Assign (lhs : Ident , rhs) if lhs.symbol.name.is(TailLocalName ) =>
198+ tailArgOrPureExpr(rhs) || varForRewrittenThis.exists(_ == lhs.symbol && rhs.tpe.isStable)
198199 case Assign (lhs : Ident , rhs : Ident ) => lhs.symbol == rhs.symbol
199200 case stat : Ident if stat.symbol.name.is(TailLocalName ) => true
200201 case _ => tpd.isPureExpr(stat)
@@ -343,6 +344,9 @@ class TailRec extends MiniPhase {
343344 case prefix : This if prefix.symbol == enclosingClass =>
344345 // Avoid assigning `this = this`
345346 assignParamPairs
347+ case prefix if prefix.symbol.is(Module ) && prefix.symbol.moduleClass == enclosingClass =>
348+ // Avoid assigning `this = MyObject`
349+ assignParamPairs
346350 case _ =>
347351 (getVarForRewrittenThis(), noTailTransform(prefix)) :: assignParamPairs
348352
Original file line number Diff line number Diff line change 1+
2+ enum Test :
3+ case One
4+ case Two (i : Int )
5+
6+ object Test :
7+ object Two :
8+ def apply (i : Int ): Test .Two = Test .Two (i) // warn
9+ def apply (i : Int , j : Int ): Test .Two = new Test .Two (i+ j)
10+ def apply (i : Int , s : String ): Two = Two (i, s) // warn because unprefixed Two is deemed pure
11+ def apply (): Test .Two = other.apply() // nowarn prefix is method call
12+ def other : this .type = this
13+
14+ object R extends Runnable :
15+ def r : this .type = this
16+ override def run () = r.run()
17+
18+ final class C (c : C ):
19+ def f (i : Int ): Int = c.f(i)
20+
21+ @ main def main = println :
22+ Test .Two (1 )
You can’t perform that action at this time.
0 commit comments