@@ -350,14 +350,14 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
350
350
var candidate : Context = NoContext
351
351
var importer : ImportSelector | Null = null // non-null for import context
352
352
var precedence = NoPrecedence // of current resolution
353
+ var enclosed = false // true if sym is owner of an enclosing context
353
354
var done = false
354
355
val ctxs = ctx.outersIterator
355
356
while ! done && ctxs.hasNext do
356
357
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
361
361
if cur.owner eq sym.owner then
362
362
done = true // for local def, just checking that it is not enclosing
363
363
else
@@ -381,7 +381,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
381
381
candidate = cur
382
382
importer = sel
383
383
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
385
385
precedence = Definition
386
386
candidate = cur
387
387
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
391
391
candidate = cur
392
392
end while
393
393
// record usage and possibly an import
394
- refInfos.refs.addOne(sym)
394
+ if ! enclosed then
395
+ refInfos.refs.addOne(sym)
395
396
if candidate != NoContext && candidate.isImportContext && importer != null then
396
397
refInfos.sels.put(importer, ())
397
398
end resolveUsage
0 commit comments