@@ -66,6 +66,10 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
6666 // import x.y; y may be rewritten x.y, also import x.z as y
6767 override def transformSelect (tree : Select )(using Context ): tree.type =
6868 val name = tree.removeAttachment(OriginalName ).getOrElse(nme.NO_NAME )
69+ inline def isImportable = tree.qualifier.srcPos.isSynthetic
70+ && tree.qualifier.tpe.match
71+ case ThisType (_) | SuperType (_, _) => false
72+ case qualtpe => qualtpe.isStable
6973 if tree.srcPos.isSynthetic && tree.symbol == defn.TypeTest_unapply then
7074 tree.qualifier.tpe.underlying.finalResultType match
7175 case AppliedType (tycon, args) =>
@@ -76,10 +80,10 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
7680 val target = res.dealias.typeSymbol
7781 resolveUsage(target, target.name, res.importPrefix.skipPackageObject) // case _: T =>
7882 case _ =>
79- else if tree.qualifier.srcPos.isSynthetic && tree.qualifier.tpe.isStable || name.exists(_ != tree.symbol.name) then
83+ else if isImportable || name.exists(_ != tree.symbol.name) then
8084 if ! ignoreTree(tree) then
8185 resolveUsage(tree.symbol, name, tree.qualifier.tpe)
82- else
86+ else if ! ignoreTree(tree) then
8387 refUsage(tree.symbol)
8488 tree
8589
@@ -304,7 +308,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
304308 case none =>
305309
306310 // Avoid spurious NoSymbol and also primary ctors which are never warned about.
307- if ! sym.exists || sym.isPrimaryConstructor then return
311+ // Selections C.this.toString should be already excluded, but backtopped here for eq, etc.
312+ if ! sym.exists || sym.isPrimaryConstructor || defn.topClasses(sym.owner) then return
308313
309314 // Find the innermost, highest precedence. Contexts have no nesting levels but assume correctness.
310315 // If the sym is an enclosing definition (the owner of a context), it does not count toward usages.
@@ -442,7 +447,6 @@ object CheckUnused:
442447 if (tree.symbol ne NoSymbol ) && ! tree.name.isWildcard then
443448 defs.addOne((tree.symbol, tree.namePos))
444449 case _ =>
445- // println(s"OTHER ${tree.symbol}")
446450 if tree.symbol ne NoSymbol then
447451 defs.addOne((tree.symbol, tree.srcPos))
448452
0 commit comments