Skip to content

Commit 77a8f13

Browse files
committed
Fix wunused false positive when deriving alias type
1 parent 6c05e6c commit 77a8f13

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,14 +565,22 @@ object CheckUnused:
565565
/** Given an import and accessibility, return an option of selector that match import<->symbol */
566566
private def isInImport(imp: tpd.Import, isAccessible: Boolean, symName: Option[Name])(using Context): Option[ImportSelector] =
567567
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)
569570
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
570574
def wildcard = sels.find(sel => sel.isWildcard && ((sym.is(Given) == sel.isGiven) || sym.is(Implicit)))
571575
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)
573577
else
574578
None
575579

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
576584
/** Annotated with @unused */
577585
private def isUnusedAnnot(using Context): Boolean =
578586
sym.annotations.exists(a => a.symbol == ctx.definitions.UnusedAnnot)

libste

Whitespace-only changes.

0 commit comments

Comments
 (0)