Skip to content

Exclude synthetic this.m, Any.m from import lookup #22695

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
Mar 4, 2025
Merged
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
12 changes: 8 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
// import x.y; y may be rewritten x.y, also import x.z as y
override def transformSelect(tree: Select)(using Context): tree.type =
val name = tree.removeAttachment(OriginalName).getOrElse(nme.NO_NAME)
inline def isImportable = tree.qualifier.srcPos.isSynthetic
&& tree.qualifier.tpe.match
case ThisType(_) | SuperType(_, _) => false
case qualtpe => qualtpe.isStable
if tree.srcPos.isSynthetic && tree.symbol == defn.TypeTest_unapply then
tree.qualifier.tpe.underlying.finalResultType match
case AppliedType(tycon, args) =>
Expand All @@ -76,10 +80,10 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
val target = res.dealias.typeSymbol
resolveUsage(target, target.name, res.importPrefix.skipPackageObject) // case _: T =>
case _ =>
else if tree.qualifier.srcPos.isSynthetic && tree.qualifier.tpe.isStable || name.exists(_ != tree.symbol.name) then
else if isImportable || name.exists(_ != tree.symbol.name) then
if !ignoreTree(tree) then
resolveUsage(tree.symbol, name, tree.qualifier.tpe)
else
else if !ignoreTree(tree) then
refUsage(tree.symbol)
tree

Expand Down Expand Up @@ -313,7 +317,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
case none =>

// Avoid spurious NoSymbol and also primary ctors which are never warned about.
if !sym.exists || sym.isPrimaryConstructor then return
// Selections C.this.toString should be already excluded, but backtopped here for eq, etc.
if !sym.exists || sym.isPrimaryConstructor || defn.topClasses(sym.owner) then return

// Find the innermost, highest precedence. Contexts have no nesting levels but assume correctness.
// If the sym is an enclosing definition (the owner of a context), it does not count toward usages.
Expand Down Expand Up @@ -451,7 +456,6 @@ object CheckUnused:
if (tree.symbol ne NoSymbol) && !tree.name.isWildcard then
defs.addOne((tree.symbol, tree.namePos))
case _ =>
//println(s"OTHER ${tree.symbol}")
if tree.symbol ne NoSymbol then
defs.addOne((tree.symbol, tree.srcPos))

Expand Down
Loading