@@ -7,7 +7,7 @@ import dotty.tools.dotc.config.ScalaSettings
7
7
import dotty .tools .dotc .core .Contexts .*
8
8
import dotty .tools .dotc .core .Flags .*
9
9
import dotty .tools .dotc .core .Names .{Name , SimpleName , DerivedName , TermName , termName }
10
- import dotty .tools .dotc .core .NameOps .{isAnonymousFunctionName , isReplWrapperName }
10
+ import dotty .tools .dotc .core .NameOps .{isAnonymousFunctionName , isReplWrapperName , setterName }
11
11
import dotty .tools .dotc .core .NameKinds .{
12
12
BodyRetainerName , ContextBoundParamName , ContextFunctionParamName , DefaultGetterName , WildcardParamName }
13
13
import dotty .tools .dotc .core .StdNames .nme
@@ -505,7 +505,13 @@ object CheckUnused:
505
505
if sym.isLocalToBlock then
506
506
if ctx.settings.WunusedHas .locals && sym.is(Mutable ) && ! infos.asss(sym) then
507
507
warnAt(pos)(UnusedSymbol .unsetLocals)
508
- else if ctx.settings.WunusedHas .privates && sym.isAllOf(Private | Mutable ) && ! infos.asss(sym) then
508
+ else if ctx.settings.WunusedHas .privates
509
+ && sym.is(Mutable )
510
+ && sym.isEffectivelyPrivate
511
+ && ! sym.isSetter // tracks sym.underlyingSymbol sibling getter, check setter below
512
+ && ! infos.asss(sym)
513
+ && ! infos.refs(sym.owner.info.member(sym.name.asTermName.setterName).symbol)
514
+ then
509
515
warnAt(pos)(UnusedSymbol .unsetPrivates)
510
516
511
517
def checkPrivate (sym : Symbol , pos : SrcPos ) =
@@ -514,7 +520,10 @@ object CheckUnused:
514
520
&& ! sym.isOneOf(SelfName | Synthetic | CaseAccessor )
515
521
&& ! sym.name.is(BodyRetainerName )
516
522
&& ! sym.isSerializationSupport
517
- && ! (sym.is(Mutable ) && sym.isSetter && sym.owner.is(Trait )) // tracks sym.underlyingSymbol sibling getter
523
+ && ! ( sym.is(Mutable )
524
+ && sym.isSetter // tracks sym.underlyingSymbol sibling getter
525
+ && (sym.owner.is(Trait ) || sym.owner.isAnonymousClass)
526
+ )
518
527
&& ! infos.nowarn(sym)
519
528
then
520
529
warnAt(pos)(UnusedSymbol .privateMembers)
0 commit comments