@@ -338,15 +338,15 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
338338 var cachePoint : Context = NoContext // last context with Resolved cache
339339 var importer : ImportSelector | Null = null // non-null for import context
340340 var precedence = NoPrecedence // of current resolution
341+ var enclosed = false // true if sym is owner of an enclosing context
341342 var done = false
342343 var cached = false
343344 val ctxs = ctx.outersIterator
344345 while ! done && ctxs.hasNext do
345346 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
350350 if cur.owner eq sym.owner then
351351 done = true // for local def, just checking that it is not enclosing
352352 else
@@ -387,7 +387,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
387387 candidate = cur
388388 importer = sel
389389 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
391391 precedence = Definition
392392 candidate = cur
393393 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
397397 candidate = cur
398398 end while
399399 // record usage and possibly an import
400- refInfos.refs.addOne(sym)
400+ if ! enclosed then
401+ refInfos.refs.addOne(sym)
401402 if candidate != NoContext && candidate.isImportContext && importer != null then
402403 refInfos.sels.put(importer, ())
403404 // possibly record that we have performed this look-up
0 commit comments