Skip to content

Commit 520e81a

Browse files
Merge pull request #3154 from dotty-staging/make-tailrec
Make isEffectivelyMutable tailrec
2 parents c3917eb + 5ab8ee2 commit 520e81a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo}
1212
import config.Printers.simplify
1313
import ast.tpd
1414

15+
import scala.annotation.tailrec
16+
1517
/** This phase consists of a series of small, simple, local optimisations
1618
* applied as a fix point transformation over Dotty Trees.
1719
*
@@ -160,10 +162,14 @@ object Simplify {
160162
* System members are the only static final fields that are mutable.
161163
* See https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5.4
162164
*/
163-
def isEffectivelyMutable(t: Tree)(implicit ctx: Context): Boolean = t match {
165+
@tailrec def isEffectivelyMutable(t: Tree)(implicit ctx: Context): Boolean = t match {
164166
case _ if t.symbol.is(Mutable) => true
165167
case s: Select => s.symbol.owner == defn.SystemModule
166-
case i: Ident => desugarIdent(i).exists(isEffectivelyMutable)
168+
case i: Ident =>
169+
desugarIdent(i) match {
170+
case Some(ident) => isEffectivelyMutable(ident)
171+
case None => false
172+
}
167173
case _ => false
168174
}
169175

0 commit comments

Comments
 (0)