@@ -370,22 +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.userSymbol eq sym then
379
- if sym.is(Package ) then
380
- if cur.isSimplePackage then
381
- precedence = Definition
382
- importer = null
383
- // else package p.q is not available as a simple name but it might be imported
384
- end if
385
- done = true
386
- else
387
- return // found enclosing definition, don't register the reference
388
- 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
389
382
if cur.owner eq sym.owner then
390
383
done = true // for local def, just checking that it is not enclosing
391
384
else
@@ -426,7 +419,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
426
419
candidate = cur
427
420
importer = sel
428
421
else if checkMember(cur.owner) then
429
- if sym.srcPos.sourcePos.source == ctx.source then
422
+ if sym.is( Package ) || sym. srcPos.sourcePos.source == ctx.source then
430
423
precedence = Definition
431
424
candidate = cur
432
425
importer = null // ignore import in same scope; we can't check nesting level
@@ -436,7 +429,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
436
429
candidate = cur
437
430
end while
438
431
// record usage and possibly an import
439
- refInfos.refs.addOne(sym)
432
+ if ! enclosed then
433
+ refInfos.refs.addOne(sym)
440
434
if candidate != NoContext && candidate.isImportContext && importer != null then
441
435
refInfos.sels.put(importer, ())
442
436
// possibly record that we have performed this look-up
@@ -970,23 +964,6 @@ object CheckUnused:
970
964
inline def userSymbol : Symbol =
971
965
if sym.denot.is(ModuleClass ) then sym.denot.companionModule else sym
972
966
973
- extension (cur : Context )
974
- def isSimplePackage (using Context ): Boolean = cur.owner.is(Package ) && {
975
- val location = cur.owner.showFullName
976
- val enclosing = cur.outersIterator
977
- .takeWhile(c => ! c.owner.isEmptyPackage && ! (c.isImportContext && c.importInfo.nn.isRootImport))
978
- .find(c => c.owner.userSymbol ne cur.owner.userSymbol)
979
- enclosing match
980
- case Some (outer) =>
981
- outer.owner.is(Package ) // if there is such an outer context, its owner should be package
982
- && ! location
983
- .stripPrefix(outer.owner.showFullName) // p.q in p.q.r
984
- .stripPrefix(" ." ) // leading dot in .r
985
- .contains(" ." ) // remaining r so p.q.v.w leaves v.w
986
- case _ =>
987
- ! location.contains(" ." ) // no outer context contributes a name, effectively _root_.p.q
988
- }
989
-
990
967
extension (sel : ImportSelector )
991
968
def boundTpe : Type = sel.bound match
992
969
case untpd.TypedSplice (tree) => tree.tpe
0 commit comments