Skip to content

Commit

Permalink
Fix wunused for deriving alias type that has a different name
Browse files Browse the repository at this point in the history
  • Loading branch information
szymon-rd committed Apr 3, 2023
1 parent 1d6ccf8 commit debfbc1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,12 @@ object CheckUnused:
private def isInImport(imp: tpd.Import, isAccessible: Boolean, symName: Option[Name])(using Context): Option[ImportSelector] =
val tpd.Import(qual, sels) = imp
val dealiasedSym = dealias(sym)
val qualHasSymbol = qual.tpe.member(sym.name).alternatives.map(_.symbol).map(dealias).contains(dealiasedSym)
val typeSelections = sels.flatMap(n => qual.tpe.member(n.name.toTypeName).alternatives)
val termSelections = sels.flatMap(n => qual.tpe.member(n.name.toTermName).alternatives)
val allSelections = typeSelections ::: termSelections :::qual.tpe.member(sym.name).alternatives
val qualHasSymbol = allSelections.map(_.symbol).map(dealias).contains(dealiasedSym)
def selector = sels.find(sel => (sel.name.toTermName == sym.name || sel.name.toTypeName == sym.name) && symName.map(n => n.toTermName == sel.rename).getOrElse(true))
def dealiasedSelector = sels.flatMap(sel => qual.tpe.member(sym.name).alternatives.map(m => (sel, m.symbol))).collect {
def dealiasedSelector = sels.flatMap(sel => allSelections.map(m => (sel, m.symbol))).collect {
case (sel, sym) if dealias(sym) == dealiasedSym => sel
}.headOption
def wildcard = sels.find(sel => sel.isWildcard && ((sym.is(Given) == sel.isGiven) || sym.is(Implicit)))
Expand Down
11 changes: 11 additions & 0 deletions tests/neg-custom-args/fatal-warnings/i15503i.scala
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,14 @@ package foo.test.i16679b:
import Foo.x
case class CoolClass(i: Int)
println(summon[myPackage.CaseClassName[CoolClass]])

package foo.test.i17156:
package a:
trait Foo[A]

package b:
type Xd = Foo

package c:
import b.Xd
trait Z derives Xd

0 comments on commit debfbc1

Please sign in to comment.