@@ -370,22 +370,15 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
370
370
var cachePoint : Context = NoContext // last context with Resolved cache
371
371
var importer : ImportSelector | Null = null // non-null for import context
372
372
var precedence = NoPrecedence // of current resolution
373
+ var enclosed = false // true if sym is owner of an enclosing context
373
374
var done = false
374
375
var cached = false
375
376
val ctxs = ctx.outersIterator
376
377
while ! done && ctxs.hasNext do
377
378
val cur = ctxs.next()
378
- if cur.owner.userSymbol eq sym then
379
- if sym.is(Package ) then
380
- if cur.isSimplePackage then
381
- precedence = Definition
382
- importer = null
383
- // else package p.q is not available as a simple name but it might be imported
384
- end if
385
- done = true
386
- else
387
- return // found enclosing definition, don't register the reference
388
- else if isLocal then
379
+ if cur.owner.userSymbol == sym && ! sym.is(Package ) then
380
+ enclosed = true // found enclosing definition, don't register the reference
381
+ if isLocal then
389
382
if cur.owner eq sym.owner then
390
383
done = true // for local def, just checking that it is not enclosing
391
384
else
@@ -426,7 +419,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
426
419
candidate = cur
427
420
importer = sel
428
421
else if checkMember(cur.owner) then
429
- if sym.srcPos.sourcePos.source == ctx.source then
422
+ if sym.is( Package ) || sym. srcPos.sourcePos.source == ctx.source then
430
423
precedence = Definition
431
424
candidate = cur
432
425
importer = null // ignore import in same scope; we can't check nesting level
@@ -436,7 +429,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
436
429
candidate = cur
437
430
end while
438
431
// record usage and possibly an import
439
- refInfos.refs.addOne(sym)
432
+ if ! enclosed then
433
+ refInfos.refs.addOne(sym)
440
434
if candidate != NoContext && candidate.isImportContext && importer != null then
441
435
refInfos.sels.put(importer, ())
442
436
// possibly record that we have performed this look-up
@@ -970,6 +964,7 @@ object CheckUnused:
970
964
inline def userSymbol : Symbol =
971
965
if sym.denot.is(ModuleClass ) then sym.denot.companionModule else sym
972
966
967
+ /*
973
968
extension (cur: Context)
974
969
def isSimplePackage(using Context): Boolean = cur.owner.is(Package) && {
975
970
val location = cur.owner.showFullName
@@ -986,6 +981,7 @@ object CheckUnused:
986
981
case _ =>
987
982
!location.contains(".") // no outer context contributes a name, effectively _root_.p.q
988
983
}
984
+ */
989
985
990
986
extension (sel : ImportSelector )
991
987
def boundTpe : Type = sel.bound match
0 commit comments