@@ -589,14 +589,22 @@ object CheckUnused:
589589 /** Given an import and accessibility, return an option of selector that match import<->symbol */
590590 private def isInImport (imp : tpd.Import , isAccessible : Boolean , symName : Option [Name ])(using Context ): Option [ImportSelector ] =
591591 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)
593594 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
594598 def wildcard = sels.find(sel => sel.isWildcard && ((sym.is(Given ) == sel.isGiven) || sym.is(Implicit )))
595599 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)
597601 else
598602 None
599603
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
600608 /** Annotated with @unused */
601609 private def isUnusedAnnot (using Context ): Boolean =
602610 sym.annotations.exists(a => a.symbol == ctx.definitions.UnusedAnnot )
0 commit comments