@@ -337,7 +337,7 @@ object CheckUnused:
337
337
* - usage
338
338
*/
339
339
private class UnusedData :
340
- import collection .mutable .{Set => MutSet , Map => MutMap , Stack => MutStack }
340
+ import collection .mutable .{Set => MutSet , Map => MutMap , Stack => MutStack , ListBuffer => MutList }
341
341
import UnusedData .*
342
342
343
343
/** The current scope during the tree traversal */
@@ -346,7 +346,7 @@ object CheckUnused:
346
346
var unusedAggregate : Option [UnusedResult ] = None
347
347
348
348
/* IMPORTS */
349
- private val impInScope = MutStack (MutSet [tpd.Import ]())
349
+ private val impInScope = MutStack (MutList [tpd.Import ]())
350
350
/**
351
351
* We store the symbol along with their accessibility without import.
352
352
* Accessibility to their definition in outer context/scope
@@ -449,7 +449,7 @@ object CheckUnused:
449
449
def pushScope (newScopeType : ScopeType ): Unit =
450
450
// unused imports :
451
451
currScopeType.push(newScopeType)
452
- impInScope.push(MutSet ())
452
+ impInScope.push(MutList ())
453
453
usedInScope.push(MutSet ())
454
454
455
455
def registerSetVar (sym : Symbol ): Unit =
@@ -669,8 +669,10 @@ object CheckUnused:
669
669
val simpleSelections = qual.tpe.member(sym.name).alternatives
670
670
val typeSelections = sels.flatMap(n => qual.tpe.member(n.name.toTypeName).alternatives)
671
671
val termSelections = sels.flatMap(n => qual.tpe.member(n.name.toTermName).alternatives)
672
+ val sameTermPath = qual.isTerm && sym.exists && sym.owner.isType && qual.tpe.typeSymbol == sym.owner.asType
672
673
val selectionsToDealias = typeSelections ::: termSelections
673
- val qualHasSymbol = simpleSelections.map(_.symbol).contains(sym) || (simpleSelections ::: selectionsToDealias).map(_.symbol).map(dealias).contains(dealiasedSym)
674
+ val renamedSelection = if sameTermPath then sels.find(sel => sel.imported.name == sym.name) else None
675
+ val qualHasSymbol = simpleSelections.map(_.symbol).contains(sym) || (simpleSelections ::: selectionsToDealias).map(_.symbol).map(dealias).contains(dealiasedSym) || renamedSelection.isDefined
674
676
def selector = sels.find(sel => (sel.name.toTermName == sym.name || sel.name.toTypeName == sym.name) && symName.map(n => n.toTermName == sel.rename).getOrElse(true ))
675
677
def dealiasedSelector = if (isDerived) sels.flatMap(sel => selectionsToDealias.map(m => (sel, m.symbol))).collect {
676
678
case (sel, sym) if dealias(sym) == dealiasedSym => sel
@@ -680,7 +682,7 @@ object CheckUnused:
680
682
else None
681
683
def wildcard = sels.find(sel => sel.isWildcard && ((sym.is(Given ) == sel.isGiven && sel.bound.isEmpty) || sym.is(Implicit )))
682
684
if qualHasSymbol && (! isAccessible || sym.isRenamedSymbol(symName)) && sym.exists then
683
- selector.orElse(dealiasedSelector).orElse(givenSelector).orElse(wildcard) // selector with name or wildcard (or given)
685
+ selector.orElse(dealiasedSelector).orElse(givenSelector).orElse(wildcard).orElse(renamedSelection) // selector with name or wildcard (or given)
684
686
else
685
687
None
686
688
0 commit comments