@@ -36,11 +36,10 @@ import dotty.tools.dotc.util.Spans.Span
3636import scala .math .Ordering
3737import scala .util .chaining .given
3838
39- /**
40- * A compiler phase that checks for unused imports or definitions
39+ /** A compiler phase that checks for unused imports or definitions.
4140 *
42- * Basically, it gathers definition/imports and their usage. If a
43- * definition/imports does not have any usage, then it is reported .
41+ * Every construct that introduces a name must have at least one corresponding reference.
42+ * The analysis is restricted to definitions of limited scope, i.e., private and local definitions .
4443 */
4544class CheckUnused private (phaseMode : CheckUnused .PhaseMode , suffix : String , _key : Property .Key [CheckUnused .UnusedData ]) extends MiniPhase :
4645 import CheckUnused .*
@@ -726,7 +725,7 @@ object CheckUnused:
726725 sym.annotations.exists(a => a.symbol == ctx.definitions.UnusedAnnot )
727726
728727 private def shouldNotReportParamOwner (using Context ): Boolean =
729- if sym.exists then
728+ sym.exists && {
730729 val owner = sym.owner
731730 trivialDefs(owner) || // is a trivial def
732731 owner.isPrimaryConstructor ||
@@ -735,18 +734,17 @@ object CheckUnused:
735734 ) ||
736735 owner.isAllOf(Synthetic | PrivateLocal ) ||
737736 owner.is(Accessor ) ||
738- owner.isOverriden
739- else
740- false
737+ owner.isOverridden
738+ }
741739
742740 private def usedDefContains (using Context ): Boolean =
743741 sym.everySymbol.exists(usedDef.apply)
744742
745743 private def everySymbol (using Context ): List [Symbol ] =
746744 List (sym, sym.companionClass, sym.companionModule, sym.moduleClass).filter(_.exists)
747745
748- /** A function is overriden . Either has `override flags` or parent has a matching member (type and name) */
749- private def isOverriden (using Context ): Boolean =
746+ /** A function is overridden . Either has `override flags` or parent has a matching member (type and name) */
747+ private def isOverridden (using Context ): Boolean =
750748 sym.is(Flags .Override ) || (sym.exists && sym.owner.thisType.parents.exists(p => sym.matchingMember(p).exists))
751749
752750 end extension
0 commit comments