@@ -441,6 +441,7 @@ object CheckUnused:
441
441
val refs = mutable.Set .empty[Symbol ] // references
442
442
val asss = mutable.Set .empty[Symbol ] // targets of assignment
443
443
val skip = mutable.Set .empty[Symbol ] // methods to skip (don't warn about their params)
444
+ val nowarn = mutable.Set .empty[Symbol ] // marked @nowarn
444
445
val imps = new IdentityHashMap [Import , Unit ] // imports
445
446
val sels = new IdentityHashMap [ImportSelector , Unit ] // matched selectors
446
447
def register (tree : Tree )(using Context ): Unit = if inlined.isEmpty then
@@ -453,17 +454,20 @@ object CheckUnused:
453
454
then
454
455
imps.put(imp, ())
455
456
case tree : Bind =>
456
- if ! tree.name.isInstanceOf [DerivedName ] && ! tree.name.is(WildcardParamName ) && ! tree.hasAttachment(NoWarn ) then
457
+ if ! tree.name.isInstanceOf [DerivedName ] && ! tree.name.is(WildcardParamName ) then
458
+ if tree.hasAttachment(NoWarn ) then
459
+ nowarn.addOne(tree.symbol)
457
460
pats.addOne((tree.symbol, tree.namePos))
458
461
case tree : NamedDefTree =>
459
462
if tree.hasAttachment(PatternVar ) then
460
463
if ! tree.name.isInstanceOf [DerivedName ] then
461
464
pats.addOne((tree.symbol, tree.namePos))
462
465
else if (tree.symbol ne NoSymbol )
463
466
&& ! tree.name.isWildcard
464
- && ! tree.hasAttachment(NoWarn )
465
467
&& ! tree.symbol.is(ModuleVal ) // track only the ModuleClass using the object symbol, with correct namePos
466
468
then
469
+ if tree.hasAttachment(NoWarn ) then
470
+ nowarn.addOne(tree.symbol)
467
471
defs.addOne((tree.symbol.userSymbol, tree.namePos))
468
472
case _ =>
469
473
if tree.symbol ne NoSymbol then
@@ -531,6 +535,7 @@ object CheckUnused:
531
535
&& ! sym.name.is(BodyRetainerName )
532
536
&& ! sym.isSerializationSupport
533
537
&& ! (sym.is(Mutable ) && sym.isSetter && sym.owner.is(Trait )) // tracks sym.underlyingSymbol sibling getter
538
+ && ! infos.nowarn(sym)
534
539
then
535
540
warnAt(pos)(UnusedSymbol .privateMembers)
536
541
@@ -627,7 +632,7 @@ object CheckUnused:
627
632
val byPos = infos.pats.groupMap(uniformPos(_, _))((sym, pos) => sym)
628
633
for (pos, syms) <- byPos if pos.span.exists && ! syms.exists(_.hasAnnotation(defn.UnusedAnnot )) do
629
634
if ! syms.exists(infos.refs(_)) then
630
- if ! syms.exists(v => ! v.isLocal && ! v.is(Private )) then
635
+ if ! syms.exists(v => ! v.isLocal && ! v.is(Private ) || infos.nowarn(v) ) then
631
636
warnAt(pos)(UnusedSymbol .patVars)
632
637
else if syms.exists(_.is(Mutable )) then // check unassigned var
633
638
val sym = // recover the original
0 commit comments