@@ -36,11 +36,10 @@ import dotty.tools.dotc.util.Spans.Span
36
36
import scala .math .Ordering
37
37
import scala .util .chaining .given
38
38
39
- /**
40
- * A compiler phase that checks for unused imports or definitions
39
+ /** A compiler phase that checks for unused imports or definitions.
41
40
*
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 .
44
43
*/
45
44
class CheckUnused private (phaseMode : CheckUnused .PhaseMode , suffix : String , _key : Property .Key [CheckUnused .UnusedData ]) extends MiniPhase :
46
45
import CheckUnused .*
@@ -726,7 +725,7 @@ object CheckUnused:
726
725
sym.annotations.exists(a => a.symbol == ctx.definitions.UnusedAnnot )
727
726
728
727
private def shouldNotReportParamOwner (using Context ): Boolean =
729
- if sym.exists then
728
+ sym.exists && {
730
729
val owner = sym.owner
731
730
trivialDefs(owner) || // is a trivial def
732
731
owner.isPrimaryConstructor ||
@@ -735,18 +734,17 @@ object CheckUnused:
735
734
) ||
736
735
owner.isAllOf(Synthetic | PrivateLocal ) ||
737
736
owner.is(Accessor ) ||
738
- owner.isOverriden
739
- else
740
- false
737
+ owner.isOverridden
738
+ }
741
739
742
740
private def usedDefContains (using Context ): Boolean =
743
741
sym.everySymbol.exists(usedDef.apply)
744
742
745
743
private def everySymbol (using Context ): List [Symbol ] =
746
744
List (sym, sym.companionClass, sym.companionModule, sym.moduleClass).filter(_.exists)
747
745
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 =
750
748
sym.is(Flags .Override ) || (sym.exists && sym.owner.thisType.parents.exists(p => sym.matchingMember(p).exists))
751
749
752
750
end extension
0 commit comments