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