@@ -441,6 +441,7 @@ object CheckUnused:
441441 val refs = mutable.Set .empty[Symbol ] // references
442442 val asss = mutable.Set .empty[Symbol ] // targets of assignment
443443 val skip = mutable.Set .empty[Symbol ] // methods to skip (don't warn about their params)
444+ val nowarn = mutable.Set .empty[Symbol ] // marked @nowarn
444445 val imps = new IdentityHashMap [Import , Unit ] // imports
445446 val sels = new IdentityHashMap [ImportSelector , Unit ] // matched selectors
446447 def register (tree : Tree )(using Context ): Unit = if inlined.isEmpty then
@@ -453,17 +454,20 @@ object CheckUnused:
453454 then
454455 imps.put(imp, ())
455456 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)
457460 pats.addOne((tree.symbol, tree.namePos))
458461 case tree : NamedDefTree =>
459462 if tree.hasAttachment(PatternVar ) then
460463 if ! tree.name.isInstanceOf [DerivedName ] then
461464 pats.addOne((tree.symbol, tree.namePos))
462465 else if (tree.symbol ne NoSymbol )
463466 && ! tree.name.isWildcard
464- && ! tree.hasAttachment(NoWarn )
465467 && ! tree.symbol.is(ModuleVal ) // track only the ModuleClass using the object symbol, with correct namePos
466468 then
469+ if tree.hasAttachment(NoWarn ) then
470+ nowarn.addOne(tree.symbol)
467471 defs.addOne((tree.symbol.userSymbol, tree.namePos))
468472 case _ =>
469473 if tree.symbol ne NoSymbol then
@@ -531,6 +535,7 @@ object CheckUnused:
531535 && ! sym.name.is(BodyRetainerName )
532536 && ! sym.isSerializationSupport
533537 && ! (sym.is(Mutable ) && sym.isSetter && sym.owner.is(Trait )) // tracks sym.underlyingSymbol sibling getter
538+ && ! infos.nowarn(sym)
534539 then
535540 warnAt(pos)(UnusedSymbol .privateMembers)
536541
@@ -627,7 +632,7 @@ object CheckUnused:
627632 val byPos = infos.pats.groupMap(uniformPos(_, _))((sym, pos) => sym)
628633 for (pos, syms) <- byPos if pos.span.exists && ! syms.exists(_.hasAnnotation(defn.UnusedAnnot )) do
629634 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
631636 warnAt(pos)(UnusedSymbol .patVars)
632637 else if syms.exists(_.is(Mutable )) then // check unassigned var
633638 val sym = // recover the original
0 commit comments