Skip to content

Commit d6696d8

Browse files
committed
Refactor unsetVarsFromUsedSym to .isUnsetVarDef
1 parent d4bd097 commit d6696d8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ object CheckUnused:
520520
.filterNot(d => usedInPosition.exists { case (pos, name) => d.span.contains(pos.span) && name == d.symbol.name})
521521
.filterNot(d => containsSyntheticSuffix(d.symbol))
522522
.map(d => UnusedSymbol(d.namePos, d.name, WarnTypes.LocalDefs)).toList
523-
val unsetLocalDefs = unsetVarsFromUsedSym(usedLocalDefs).map(d => UnusedSymbol(d.namePos, d.name, WarnTypes.UnsetLocals)).toList
523+
val unsetLocalDefs = usedLocalDefs.filter(isUnsetVarDef).map(d => UnusedSymbol(d.namePos, d.name, WarnTypes.UnsetLocals)).toList
524524

525525
val sortedExplicitParams =
526526
if ctx.settings.WunusedHas.explicits then
@@ -546,7 +546,7 @@ object CheckUnused:
546546
else
547547
(Nil, Nil)
548548
val sortedPrivateDefs = unusedPrivates.filterNot(d => containsSyntheticSuffix(d.symbol)).map(d => UnusedSymbol(d.namePos, d.name, WarnTypes.PrivateMembers)).toList
549-
val unsetPrivateDefs = unsetVarsFromUsedSym(usedPrivates).map(d => UnusedSymbol(d.namePos, d.name, WarnTypes.UnsetPrivates)).toList
549+
val unsetPrivateDefs = usedPrivates.filter(isUnsetVarDef).map(d => UnusedSymbol(d.namePos, d.name, WarnTypes.UnsetPrivates)).toList
550550
val sortedPatVars =
551551
if ctx.settings.WunusedHas.patvars then
552552
patVarsInScope
@@ -745,10 +745,13 @@ object CheckUnused:
745745
!isSyntheticMainParam(sym) &&
746746
!sym.shouldNotReportParamOwner
747747

748-
749748
private def shouldReportPrivateDef(using Context): Boolean =
750749
currScopeType.top == ScopeType.Template && !memDef.symbol.isConstructor && memDef.symbol.is(Private, butNot = SelfName | Synthetic | CaseAccessor)
751750

751+
private def isUnsetVarDef(using Context): Boolean =
752+
val sym = memDef.symbol
753+
sym.is(Mutable) && !setVars(sym)
754+
752755
extension (imp: tpd.Import)
753756
/** Enum generate an import for its cases (but outside them), which should be ignored */
754757
def isGeneratedByEnum(using Context): Boolean =
@@ -758,9 +761,6 @@ object CheckUnused:
758761
private def isWildcard: Boolean =
759762
thisName == StdNames.nme.WILDCARD || thisName.is(WildcardParamName)
760763

761-
def unsetVarsFromUsedSym(usedDefs: Iterable[tpd.MemberDef])(using Context): Iterable[tpd.MemberDef] =
762-
usedDefs.filter(d => d.symbol.is(Mutable) && !setVars(d.symbol))
763-
764764
end UnusedData
765765

766766
private object UnusedData:

0 commit comments

Comments
 (0)