@@ -350,14 +350,14 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
350350 var candidate : Context = NoContext
351351 var importer : ImportSelector | Null = null // non-null for import context
352352 var precedence = NoPrecedence // of current resolution
353+ var enclosed = false // true if sym is owner of an enclosing context
353354 var done = false
354355 val ctxs = ctx.outersIterator
355356 while ! done && ctxs.hasNext do
356357 val cur = ctxs.next()
357- if cur.owner eq sym then
358- addCached(cachePoint, Definition )
359- return // found enclosing definition
360- else if isLocal then
358+ if cur.owner.userSymbol == sym && ! sym.is(Package ) then
359+ enclosed = true // found enclosing definition, don't register the reference
360+ if isLocal then
361361 if cur.owner eq sym.owner then
362362 done = true // for local def, just checking that it is not enclosing
363363 else
@@ -381,7 +381,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
381381 candidate = cur
382382 importer = sel
383383 else if checkMember(cur.owner) then
384- if sym.srcPos.sourcePos.source == ctx.source then
384+ if sym.is( Package ) || sym. srcPos.sourcePos.source == ctx.source then
385385 precedence = Definition
386386 candidate = cur
387387 importer = null // ignore import in same scope; we can't check nesting level
@@ -391,7 +391,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
391391 candidate = cur
392392 end while
393393 // record usage and possibly an import
394- refInfos.refs.addOne(sym)
394+ if ! enclosed then
395+ refInfos.refs.addOne(sym)
395396 if candidate != NoContext && candidate.isImportContext && importer != null then
396397 refInfos.sels.put(importer, ())
397398 end resolveUsage
0 commit comments