@@ -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 =
@@ -671,8 +671,10 @@ object CheckUnused:
671
671
val simpleSelections = qual.tpe.member(sym.name).alternatives
672
672
val typeSelections = sels.flatMap(n => qual.tpe.member(n.name.toTypeName).alternatives)
673
673
val termSelections = sels.flatMap(n => qual.tpe.member(n.name.toTermName).alternatives)
674
+ val sameTermPath = qual.isTerm && sym.exists && sym.owner.isType && qual.tpe.typeSymbol == sym.owner.asType
674
675
val selectionsToDealias = typeSelections ::: termSelections
675
- val qualHasSymbol = simpleSelections.map(_.symbol).contains(sym) || (simpleSelections ::: selectionsToDealias).map(_.symbol).map(dealias).contains(dealiasedSym)
676
+ val renamedSelection = if sameTermPath then sels.find(sel => sel.imported.name == sym.name) else None
677
+ val qualHasSymbol = simpleSelections.map(_.symbol).contains(sym) || (simpleSelections ::: selectionsToDealias).map(_.symbol).map(dealias).contains(dealiasedSym) || renamedSelection.isDefined
676
678
def selector = sels.find(sel => (sel.name.toTermName == sym.name || sel.name.toTypeName == sym.name) && symName.map(n => n.toTermName == sel.rename).getOrElse(true ))
677
679
def dealiasedSelector = if (isDerived) sels.flatMap(sel => selectionsToDealias.map(m => (sel, m.symbol))).collect {
678
680
case (sel, sym) if dealias(sym) == dealiasedSym => sel
@@ -682,7 +684,7 @@ object CheckUnused:
682
684
else None
683
685
def wildcard = sels.find(sel => sel.isWildcard && ((sym.is(Given ) == sel.isGiven && sel.bound.isEmpty) || sym.is(Implicit )))
684
686
if qualHasSymbol && (! isAccessible || sym.isRenamedSymbol(symName)) && sym.exists then
685
- selector.orElse(dealiasedSelector).orElse(givenSelector).orElse(wildcard) // selector with name or wildcard (or given)
687
+ selector.orElse(dealiasedSelector).orElse(givenSelector).orElse(wildcard).orElse(renamedSelection) // selector with name or wildcard (or given)
686
688
else
687
689
None
688
690
0 commit comments