|
1 | 1 | package dotty.tools.dotc.transform
|
2 | 2 |
|
| 3 | +import scala.annotation.tailrec |
| 4 | + |
3 | 5 | import dotty.tools.dotc.ast.tpd
|
4 | 6 | import dotty.tools.dotc.core.Symbols.*
|
5 | 7 | import dotty.tools.dotc.ast.tpd.{Inlined, TreeTraverser}
|
@@ -88,11 +90,17 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
|
88 | 90 |
|
89 | 91 | override def prepareForIdent(tree: tpd.Ident)(using Context): Context =
|
90 | 92 | if tree.symbol.exists then
|
91 |
| - val prefixes = LazyList.iterate(tree.typeOpt.normalizedPrefix)(_.normalizedPrefix).takeWhile(_ != NoType) |
92 |
| - .take(10) // Failsafe for the odd case if there was an infinite cycle |
93 |
| - for prefix <- prefixes do |
94 |
| - unusedDataApply(_.registerUsed(prefix.classSymbol, None)) |
95 |
| - unusedDataApply(_.registerUsed(tree.symbol, Some(tree.name))) |
| 93 | + unusedDataApply { ud => |
| 94 | + @tailrec |
| 95 | + def loopOnNormalizedPrefixes(prefix: Type, depth: Int): Unit = |
| 96 | + // limit to 10 as failsafe for the odd case where there is an infinite cycle |
| 97 | + if depth < 10 && prefix.exists then |
| 98 | + ud.registerUsed(prefix.classSymbol, None) |
| 99 | + loopOnNormalizedPrefixes(prefix.normalizedPrefix, depth + 1) |
| 100 | + |
| 101 | + loopOnNormalizedPrefixes(tree.typeOpt.normalizedPrefix, depth = 0) |
| 102 | + ud.registerUsed(tree.symbol, Some(tree.name)) |
| 103 | + } |
96 | 104 | else if tree.hasType then
|
97 | 105 | unusedDataApply(_.registerUsed(tree.tpe.classSymbol, Some(tree.name)))
|
98 | 106 | else
|
|
0 commit comments