File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -196,7 +196,8 @@ class TailRec extends MiniPhase {
196
196
def isInfiniteRecCall (tree : Tree ): Boolean = {
197
197
def tailArgOrPureExpr (stat : Tree ): Boolean = stat match {
198
198
case stat : ValDef if stat.name.is(TailTempName ) || ! stat.symbol.is(Mutable ) => tailArgOrPureExpr(stat.rhs)
199
- case Assign (lhs : Ident , rhs) if lhs.symbol.name.is(TailLocalName ) => tailArgOrPureExpr(rhs)
199
+ case Assign (lhs : Ident , rhs) if lhs.symbol.name.is(TailLocalName ) =>
200
+ tailArgOrPureExpr(rhs) || varForRewrittenThis.exists(_ == lhs.symbol && rhs.tpe.isStable)
200
201
case Assign (lhs : Ident , rhs : Ident ) => lhs.symbol == rhs.symbol
201
202
case stat : Ident if stat.symbol.name.is(TailLocalName ) => true
202
203
case _ => tpd.isPureExpr(stat)
@@ -345,6 +346,9 @@ class TailRec extends MiniPhase {
345
346
case prefix : This if prefix.symbol == enclosingClass =>
346
347
// Avoid assigning `this = this`
347
348
assignParamPairs
349
+ case prefix if prefix.symbol.is(Module ) && prefix.symbol.moduleClass == enclosingClass =>
350
+ // Avoid assigning `this = MyObject`
351
+ assignParamPairs
348
352
case _ =>
349
353
(getVarForRewrittenThis(), noTailTransform(prefix)) :: assignParamPairs
350
354
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 (): Test .Two = other.apply() // nowarn prefix is method call
11
+ def other : this .type = this
12
+
13
+ object R extends Runnable :
14
+ def r : this .type = this
15
+ override def run () = r.run()
16
+
17
+ final class C (c : C ):
18
+ def f (i : Int ): Int = c.f(i)
19
+
20
+ @ main def main = println :
21
+ Test .Two (1 )
You can’t perform that action at this time.
0 commit comments