@@ -370,15 +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 eq sym then
379
- addCached(cachePoint, Definition )
380
- return // found enclosing definition
381
- 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
382
382
if cur.owner eq sym.owner then
383
383
done = true // for local def, just checking that it is not enclosing
384
384
else
@@ -419,7 +419,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
419
419
candidate = cur
420
420
importer = sel
421
421
else if checkMember(cur.owner) then
422
- if sym.srcPos.sourcePos.source == ctx.source then
422
+ if sym.is( Package ) || sym. srcPos.sourcePos.source == ctx.source then
423
423
precedence = Definition
424
424
candidate = cur
425
425
importer = null // ignore import in same scope; we can't check nesting level
@@ -429,7 +429,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
429
429
candidate = cur
430
430
end while
431
431
// record usage and possibly an import
432
- refInfos.refs.addOne(sym)
432
+ if ! enclosed then
433
+ refInfos.refs.addOne(sym)
433
434
if candidate != NoContext && candidate.isImportContext && importer != null then
434
435
refInfos.sels.put(importer, ())
435
436
// possibly record that we have performed this look-up
0 commit comments