@@ -589,14 +589,22 @@ object CheckUnused:
589
589
/** Given an import and accessibility, return an option of selector that match import<->symbol */
590
590
private def isInImport (imp : tpd.Import , isAccessible : Boolean , symName : Option [Name ])(using Context ): Option [ImportSelector ] =
591
591
val tpd .Import (qual, sels) = imp
592
- val qualHasSymbol = qual.tpe.member(sym.name).alternatives.map(_.symbol).contains(sym)
592
+ val dealiasedSym = dealias(sym)
593
+ val qualHasSymbol = qual.tpe.member(sym.name).alternatives.map(_.symbol).map(dealias).contains(dealiasedSym)
593
594
def selector = sels.find(sel => (sel.name.toTermName == sym.name || sel.name.toTypeName == sym.name) && symName.map(n => n.toTermName == sel.rename).getOrElse(true ))
595
+ def dealiasedSelector = sels.flatMap(sel => qual.tpe.member(sym.name).alternatives.map(m => (sel, m.symbol))).collect {
596
+ case (sel, sym) if dealias(sym) == dealiasedSym => sel
597
+ }.headOption
594
598
def wildcard = sels.find(sel => sel.isWildcard && ((sym.is(Given ) == sel.isGiven) || sym.is(Implicit )))
595
599
if qualHasSymbol && ! isAccessible && sym.exists then
596
- selector.orElse(wildcard) // selector with name or wildcard (or given)
600
+ selector.orElse(dealiasedSelector).orElse( wildcard) // selector with name or wildcard (or given)
597
601
else
598
602
None
599
603
604
+ private def dealias (symbol : Symbol )(using Context ): Symbol =
605
+ if (symbol.isType && symbol.asType.denot.isAliasType) then
606
+ symbol.asType.typeRef.dealias.typeSymbol
607
+ else symbol
600
608
/** Annotated with @unused */
601
609
private def isUnusedAnnot (using Context ): Boolean =
602
610
sym.annotations.exists(a => a.symbol == ctx.definitions.UnusedAnnot )
0 commit comments