@@ -338,15 +338,15 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
338
338
var cachePoint : Context = NoContext // last context with Resolved cache
339
339
var importer : ImportSelector | Null = null // non-null for import context
340
340
var precedence = NoPrecedence // of current resolution
341
+ var enclosed = false // true if sym is owner of an enclosing context
341
342
var done = false
342
343
var cached = false
343
344
val ctxs = ctx.outersIterator
344
345
while ! done && ctxs.hasNext do
345
346
val cur = ctxs.next()
346
- if cur.owner eq sym then
347
- addCached(cachePoint, Definition )
348
- return // found enclosing definition
349
- else if isLocal then
347
+ if cur.owner.userSymbol == sym && ! sym.is(Package ) then
348
+ enclosed = true // found enclosing definition, don't register the reference
349
+ if isLocal then
350
350
if cur.owner eq sym.owner then
351
351
done = true // for local def, just checking that it is not enclosing
352
352
else
@@ -387,7 +387,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
387
387
candidate = cur
388
388
importer = sel
389
389
else if checkMember(cur.owner) then
390
- if sym.srcPos.sourcePos.source == ctx.source then
390
+ if sym.is( Package ) || sym. srcPos.sourcePos.source == ctx.source then
391
391
precedence = Definition
392
392
candidate = cur
393
393
importer = null // ignore import in same scope; we can't check nesting level
@@ -397,7 +397,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
397
397
candidate = cur
398
398
end while
399
399
// record usage and possibly an import
400
- refInfos.refs.addOne(sym)
400
+ if ! enclosed then
401
+ refInfos.refs.addOne(sym)
401
402
if candidate != NoContext && candidate.isImportContext && importer != null then
402
403
refInfos.sels.put(importer, ())
403
404
// possibly record that we have performed this look-up
0 commit comments