@@ -450,6 +450,7 @@ object CheckUnused:
450
450
val refs = mutable.Set .empty[Symbol ] // references
451
451
val asss = mutable.Set .empty[Symbol ] // targets of assignment
452
452
val skip = mutable.Set .empty[Symbol ] // methods to skip (don't warn about their params)
453
+ val nowarn = mutable.Set .empty[Symbol ] // marked @nowarn
453
454
val imps = new IdentityHashMap [Import , Unit ] // imports
454
455
val sels = new IdentityHashMap [ImportSelector , Unit ] // matched selectors
455
456
def register (tree : Tree )(using Context ): Unit = if inlined.isEmpty then
@@ -462,17 +463,20 @@ object CheckUnused:
462
463
then
463
464
imps.put(imp, ())
464
465
case tree : Bind =>
465
- if ! tree.name.isInstanceOf [DerivedName ] && ! tree.name.is(WildcardParamName ) && ! tree.hasAttachment(NoWarn ) then
466
+ if ! tree.name.isInstanceOf [DerivedName ] && ! tree.name.is(WildcardParamName ) then
467
+ if tree.hasAttachment(NoWarn ) then
468
+ nowarn.addOne(tree.symbol)
466
469
pats.addOne((tree.symbol, tree.namePos))
467
470
case tree : NamedDefTree =>
468
471
if tree.hasAttachment(PatternVar ) then
469
472
if ! tree.name.isInstanceOf [DerivedName ] then
470
473
pats.addOne((tree.symbol, tree.namePos))
471
474
else if (tree.symbol ne NoSymbol )
472
475
&& ! tree.name.isWildcard
473
- && ! tree.hasAttachment(NoWarn )
474
476
&& ! tree.symbol.is(ModuleVal ) // track only the ModuleClass using the object symbol, with correct namePos
475
477
then
478
+ if tree.hasAttachment(NoWarn ) then
479
+ nowarn.addOne(tree.symbol)
476
480
defs.addOne((tree.symbol.userSymbol, tree.namePos))
477
481
case _ =>
478
482
if tree.symbol ne NoSymbol then
@@ -540,6 +544,7 @@ object CheckUnused:
540
544
&& ! sym.name.is(BodyRetainerName )
541
545
&& ! sym.isSerializationSupport
542
546
&& ! (sym.is(Mutable ) && sym.isSetter && sym.owner.is(Trait )) // tracks sym.underlyingSymbol sibling getter
547
+ && ! infos.nowarn(sym)
543
548
then
544
549
warnAt(pos)(UnusedSymbol .privateMembers)
545
550
@@ -635,7 +640,7 @@ object CheckUnused:
635
640
val byPos = infos.pats.groupMap(uniformPos(_, _))((sym, pos) => sym)
636
641
for (pos, syms) <- byPos if pos.span.exists && ! syms.exists(_.hasAnnotation(defn.UnusedAnnot )) do
637
642
if ! syms.exists(infos.refs(_)) then
638
- if ! syms.exists(v => ! v.isLocal && ! v.is(Private )) then
643
+ if ! syms.exists(v => ! v.isLocal && ! v.is(Private ) || infos.nowarn(v) ) then
639
644
warnAt(pos)(UnusedSymbol .patVars)
640
645
else if syms.exists(_.is(Mutable )) then // check unassigned var
641
646
val sym = // recover the original
0 commit comments