@@ -683,36 +683,39 @@ object CheckUnused:
683
683
}
684
684
685
685
/** Given an import and accessibility, return selector that matches import<->symbol */
686
- private def isInImport (imp : tpd.Import , isAccessible : Boolean , symName : Option [Name ], isDerived : Boolean )(using Context ): Option [ImportSelector ] =
686
+ private def isInImport (imp : tpd.Import , isAccessible : Boolean , altName : Option [Name ], isDerived : Boolean )(using Context ): Option [ImportSelector ] =
687
687
val tpd .Import (qual, sels) = imp
688
- val dealiasedSym = dealias(sym)
689
- val simpleSelections = qual.tpe.member(sym.name).alternatives
690
- val typeSelections = sels.flatMap(n => qual.tpe.member(n.name.toTypeName).alternatives)
691
- val termSelections = sels.flatMap(n => qual.tpe.member(n.name.toTermName).alternatives)
692
- val sameTermPath = qual.isTerm && sym.exists && sym.owner.isType && qual.tpe.typeSymbol == sym.owner.asType
693
- val selectionsToDealias = typeSelections ::: termSelections
694
- val renamedSelection = if sameTermPath then sels.find(sel => sel.imported.name == sym.name) else None
695
- val qualHasSymbol = simpleSelections.map(_.symbol).contains(sym) || (simpleSelections ::: selectionsToDealias).map(_.symbol).map(dealias).contains(dealiasedSym) || renamedSelection.isDefined
696
- def selector = sels.find(sel => (sel.name.toTermName == sym.name || sel.name.toTypeName == sym.name) && symName.map(n => n.toTermName == sel.rename).getOrElse(true ))
697
- def dealiasedSelector = if (isDerived) sels.flatMap(sel => selectionsToDealias.map(m => (sel, m.symbol))).collect {
698
- case (sel, sym) if dealias(sym) == dealiasedSym => sel
699
- }.headOption else None
688
+ val qualTpe = qual.tpe
689
+ val dealiasedSym = sym.dealias
690
+ val simpleSelections = qualTpe.member(sym.name).alternatives
691
+ val selectionsToDealias = sels.flatMap(sel =>
692
+ qualTpe.member(sel.name.toTypeName).alternatives
693
+ ::: qualTpe.member(sel.name.toTermName).alternatives)
694
+ def qualHasSymbol = simpleSelections.map(_.symbol).contains(sym) || (simpleSelections ::: selectionsToDealias).map(_.symbol).map(_.dealias).contains(dealiasedSym)
695
+ def selector = sels.find(sel => (sel.name.toTermName == sym.name || sel.name.toTypeName == sym.name) && altName.map(n => n.toTermName == sel.rename).getOrElse(true ))
696
+ def dealiasedSelector =
697
+ if isDerived then
698
+ sels.flatMap(sel => selectionsToDealias.map(m => (sel, m.symbol))).collect {
699
+ case (sel, sym) if sym.dealias == dealiasedSym => sel
700
+ }.headOption
701
+ else None
700
702
def givenSelector = if sym.is(Given ) || sym.is(Implicit )
701
703
then sels.filter(sel => sel.isGiven && ! sel.bound.isEmpty).find(sel => sel.boundTpe =:= sym.info)
702
704
else None
703
705
def wildcard = sels.find(sel => sel.isWildcard && ((sym.is(Given ) == sel.isGiven && sel.bound.isEmpty) || sym.is(Implicit )))
704
- if qualHasSymbol && (! isAccessible || sym.isRenamedSymbol(symName)) && sym.exists then
705
- selector.orElse(dealiasedSelector).orElse(givenSelector).orElse(wildcard).orElse(renamedSelection) // selector with name or wildcard (or given)
706
+ if sym.exists && qualHasSymbol && (! isAccessible || sym.isRenamedSymbol(altName)) then
707
+ selector.orElse(dealiasedSelector).orElse(givenSelector).orElse(wildcard) // selector with name or wildcard (or given)
706
708
else
707
709
None
708
710
709
711
private def isRenamedSymbol (symNameInScope : Option [Name ])(using Context ) =
710
712
sym.name != nme.NO_NAME && symNameInScope.exists(_.toSimpleName != sym.name.toSimpleName)
711
713
712
- private def dealias (symbol : Symbol )(using Context ): Symbol =
713
- if (symbol.isType && symbol.asType.denot.isAliasType) then
714
- symbol.asType.typeRef.dealias.typeSymbol
715
- else symbol
714
+ private def dealias (using Context ): Symbol =
715
+ if sym.isType && sym.asType.denot.isAliasType then
716
+ sym.asType.typeRef.dealias.typeSymbol
717
+ else sym
718
+
716
719
/** Annotated with @unused */
717
720
private def isUnusedAnnot (using Context ): Boolean =
718
721
sym.annotations.exists(a => a.symbol == ctx.definitions.UnusedAnnot )
0 commit comments