@@ -25,6 +25,7 @@ import dotty.tools.dotc.util.chaining.*
2525
2626import java .util .IdentityHashMap
2727
28+ import scala .collection .immutable .LazyList
2829import scala .collection .mutable , mutable .{ArrayBuilder , ListBuffer , Stack }
2930
3031import CheckUnused .*
@@ -63,8 +64,22 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
6364 if depth < 10 && prefix.exists && ! prefix.classSymbol.isEffectiveRoot then
6465 resolveUsage(prefix.classSymbol, nme.NO_NAME , NoPrefix )
6566 loopOverPrefixes(prefix.normalizedPrefix, depth + 1 )
67+ /*
6668 if tree.srcPos.isZeroExtentSynthetic then
67- loopOverPrefixes(tree.typeOpt.normalizedPrefix, depth = 0 )
69+ println(s"ZES ${tree.show}")
70+ def prefixed(t: Type) =
71+ if t.exists && !t.classSymbol.isEffectiveRoot then
72+ println(s"CS ${t.classSymbol}")
73+ Some(t, t.normalizedPrefix)
74+ else
75+ None
76+ val prefixes = LazyList.unfold(tree.typeOpt)(prefixed).take(10).force
77+ println(s"PREFIXES ${prefixes}")
78+ for (prefix <- prefixes.drop(1))
79+ ()
80+ */
81+ // if tree.srcPos.isZeroExtentSynthetic then
82+ // loopOverPrefixes(tree.typeOpt.normalizedPrefix, depth = 0)
6883 resolveUsage(tree.symbol, tree.name, tree.typeOpt.importPrefix.skipPackageObject)
6984 else if tree.hasType then
7085 resolveUsage(tree.tpe.classSymbol, tree.name, tree.tpe.importPrefix.skipPackageObject)
@@ -330,7 +345,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
330345 def addCached (where : Context , result : Precedence ): Unit =
331346 if where.moreProperties ne null then
332347 where.property(resolvedKey) match
333- case Some (resolved) =>
348+ case Some (resolved) if where.owner.isLocalToBlock || where.owner.info =:= prefix =>
334349 resolved.record(sym, name, prefix, result)
335350 case none =>
336351
@@ -361,7 +376,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
361376 cur.property(resolvedKey) match
362377 case Some (resolved) =>
363378 // conservative, cache must be nested below the result context
364- if precedence.isNone then
379+ if precedence.isNone && (cur.owner.isLocalToBlock || cur.owner.info =:= prefix) then
365380 cachePoint = cur // no result yet, and future result could be cached here
366381 resolved.hasRecord(sym, name, prefix)
367382 case none => NoPrecedence
0 commit comments