Skip to content

Dealias when looking into imports #22889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha

def matchingSelector(info: ImportInfo): ImportSelector | Null =
val qtpe = info.site
def hasAltMember(nm: Name) = qtpe.member(nm).hasAltWith(_.symbol == sym)
def hasAltMember(nm: Name) = qtpe.member(nm).hasAltWith: alt =>
alt.symbol == sym
|| nm.isTypeName && alt.symbol.isAliasType && alt.info.dealias.typeSymbol == sym
def loop(sels: List[ImportSelector]): ImportSelector | Null = sels match
case sel :: sels =>
val matches =
Expand Down
19 changes: 19 additions & 0 deletions tests/warn/i22787.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//> using options -Wunused:imports -Werror

object tpd:
type Block = Trees.Block

object Trees:
abstract case class Block(x: Int)
private object Block
val block = new Block(42) {}

def f(x: Any) =
import tpd.Block
//import Trees.Block
x match
case Block(_) => "yes"
case _ => "no"

@main def test = println:
f(Trees.block)
Loading