@@ -337,7 +337,7 @@ object CheckUnused:
337337 * - usage
338338 */
339339 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 }
341341 import UnusedData .*
342342
343343 /** The current scope during the tree traversal */
@@ -346,7 +346,7 @@ object CheckUnused:
346346 var unusedAggregate : Option [UnusedResult ] = None
347347
348348 /* IMPORTS */
349- private val impInScope = MutStack (MutSet [tpd.Import ]())
349+ private val impInScope = MutStack (MutList [tpd.Import ]())
350350 /**
351351 * We store the symbol along with their accessibility without import.
352352 * Accessibility to their definition in outer context/scope
@@ -449,7 +449,7 @@ object CheckUnused:
449449 def pushScope (newScopeType : ScopeType ): Unit =
450450 // unused imports :
451451 currScopeType.push(newScopeType)
452- impInScope.push(MutSet ())
452+ impInScope.push(MutList ())
453453 usedInScope.push(MutSet ())
454454
455455 def registerSetVar (sym : Symbol ): Unit =
@@ -671,8 +671,10 @@ object CheckUnused:
671671 val simpleSelections = qual.tpe.member(sym.name).alternatives
672672 val typeSelections = sels.flatMap(n => qual.tpe.member(n.name.toTypeName).alternatives)
673673 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
674675 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
676678 def selector = sels.find(sel => (sel.name.toTermName == sym.name || sel.name.toTypeName == sym.name) && symName.map(n => n.toTermName == sel.rename).getOrElse(true ))
677679 def dealiasedSelector = if (isDerived) sels.flatMap(sel => selectionsToDealias.map(m => (sel, m.symbol))).collect {
678680 case (sel, sym) if dealias(sym) == dealiasedSym => sel
@@ -682,7 +684,7 @@ object CheckUnused:
682684 else None
683685 def wildcard = sels.find(sel => sel.isWildcard && ((sym.is(Given ) == sel.isGiven && sel.bound.isEmpty) || sym.is(Implicit )))
684686 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)
686688 else
687689 None
688690
0 commit comments