@@ -7,7 +7,7 @@ import dotty.tools.dotc.config.ScalaSettings
77import dotty .tools .dotc .core .Contexts .*
88import dotty .tools .dotc .core .Flags .*
99import dotty .tools .dotc .core .Names .{Name , SimpleName , DerivedName , TermName , termName }
10- import dotty .tools .dotc .core .NameOps .{isAnonymousFunctionName , isReplWrapperName , isContextFunction }
10+ import dotty .tools .dotc .core .NameOps .{isAnonymousFunctionName , isReplWrapperName , isContextFunction , setterName }
1111import dotty .tools .dotc .core .NameKinds .{
1212 BodyRetainerName , ContextBoundParamName , ContextFunctionParamName , DefaultGetterName , WildcardParamName }
1313import dotty .tools .dotc .core .StdNames .nme
@@ -543,7 +543,13 @@ object CheckUnused:
543543 if sym.isLocalToBlock then
544544 if ctx.settings.WunusedHas .locals && sym.is(Mutable ) && ! infos.asss(sym) then
545545 warnAt(pos)(UnusedSymbol .unsetLocals)
546- else if ctx.settings.WunusedHas .privates && sym.isAllOf(Private | Mutable ) && ! infos.asss(sym) then
546+ else if ctx.settings.WunusedHas .privates
547+ && sym.is(Mutable )
548+ && (sym.is(Private ) || sym.isEffectivelyPrivate)
549+ && ! sym.isSetter // tracks sym.underlyingSymbol sibling getter, check setter below
550+ && ! infos.asss(sym)
551+ && ! infos.refs(sym.owner.info.member(sym.name.asTermName.setterName).symbol)
552+ then
547553 warnAt(pos)(UnusedSymbol .unsetPrivates)
548554
549555 def checkPrivate (sym : Symbol , pos : SrcPos ) =
@@ -552,7 +558,10 @@ object CheckUnused:
552558 && ! sym.isOneOf(SelfName | Synthetic | CaseAccessor )
553559 && ! sym.name.is(BodyRetainerName )
554560 && ! sym.isSerializationSupport
555- && ! (sym.is(Mutable ) && sym.isSetter && sym.owner.is(Trait )) // tracks sym.underlyingSymbol sibling getter
561+ && ! ( sym.is(Mutable )
562+ && sym.isSetter // tracks sym.underlyingSymbol sibling getter
563+ && (sym.owner.is(Trait ) || sym.owner.isAnonymousClass)
564+ )
556565 && ! infos.nowarn(sym)
557566 then
558567 warnAt(pos)(UnusedSymbol .privateMembers)
0 commit comments