@@ -565,14 +565,22 @@ object CheckUnused:
565
565
/** Given an import and accessibility, return an option of selector that match import<->symbol */
566
566
private def isInImport (imp : tpd.Import , isAccessible : Boolean , symName : Option [Name ])(using Context ): Option [ImportSelector ] =
567
567
val tpd .Import (qual, sels) = imp
568
- val qualHasSymbol = qual.tpe.member(sym.name).alternatives.map(_.symbol).contains(sym)
568
+ val dealiasedSym = dealias(sym)
569
+ val qualHasSymbol = qual.tpe.member(sym.name).alternatives.map(_.symbol).map(dealias).contains(dealiasedSym)
569
570
def selector = sels.find(sel => (sel.name.toTermName == sym.name || sel.name.toTypeName == sym.name) && symName.map(n => n.toTermName == sel.rename).getOrElse(true ))
571
+ def dealiasedSelector = sels.flatMap(sel => qual.tpe.member(sym.name).alternatives.map(m => (sel, m.symbol))).collect {
572
+ case (sel, sym) if dealias(sym) == dealiasedSym => sel
573
+ }.headOption
570
574
def wildcard = sels.find(sel => sel.isWildcard && ((sym.is(Given ) == sel.isGiven) || sym.is(Implicit )))
571
575
if qualHasSymbol && ! isAccessible && sym.exists then
572
- selector.orElse(wildcard) // selector with name or wildcard (or given)
576
+ selector.orElse(dealiasedSelector).orElse( wildcard) // selector with name or wildcard (or given)
573
577
else
574
578
None
575
579
580
+ private def dealias (symbol : Symbol )(using Context ): Symbol =
581
+ if (symbol.isType && symbol.asType.denot.isAliasType) then
582
+ symbol.asType.typeRef.dealias.typeSymbol
583
+ else symbol
576
584
/** Annotated with @unused */
577
585
private def isUnusedAnnot (using Context ): Boolean =
578
586
sym.annotations.exists(a => a.symbol == ctx.definitions.UnusedAnnot )
0 commit comments