@@ -450,6 +450,7 @@ object CheckUnused:
450450 val refs = mutable.Set .empty[Symbol ] // references
451451 val asss = mutable.Set .empty[Symbol ] // targets of assignment
452452 val skip = mutable.Set .empty[Symbol ] // methods to skip (don't warn about their params)
453+ val nowarn = mutable.Set .empty[Symbol ] // marked @nowarn
453454 val imps = new IdentityHashMap [Import , Unit ] // imports
454455 val sels = new IdentityHashMap [ImportSelector , Unit ] // matched selectors
455456 def register (tree : Tree )(using Context ): Unit = if inlined.isEmpty then
@@ -462,17 +463,20 @@ object CheckUnused:
462463 then
463464 imps.put(imp, ())
464465 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)
466469 pats.addOne((tree.symbol, tree.namePos))
467470 case tree : NamedDefTree =>
468471 if tree.hasAttachment(PatternVar ) then
469472 if ! tree.name.isInstanceOf [DerivedName ] then
470473 pats.addOne((tree.symbol, tree.namePos))
471474 else if (tree.symbol ne NoSymbol )
472475 && ! tree.name.isWildcard
473- && ! tree.hasAttachment(NoWarn )
474476 && ! tree.symbol.is(ModuleVal ) // track only the ModuleClass using the object symbol, with correct namePos
475477 then
478+ if tree.hasAttachment(NoWarn ) then
479+ nowarn.addOne(tree.symbol)
476480 defs.addOne((tree.symbol.userSymbol, tree.namePos))
477481 case _ =>
478482 if tree.symbol ne NoSymbol then
@@ -540,6 +544,7 @@ object CheckUnused:
540544 && ! sym.name.is(BodyRetainerName )
541545 && ! sym.isSerializationSupport
542546 && ! (sym.is(Mutable ) && sym.isSetter && sym.owner.is(Trait )) // tracks sym.underlyingSymbol sibling getter
547+ && ! infos.nowarn(sym)
543548 then
544549 warnAt(pos)(UnusedSymbol .privateMembers)
545550
@@ -635,7 +640,7 @@ object CheckUnused:
635640 val byPos = infos.pats.groupMap(uniformPos(_, _))((sym, pos) => sym)
636641 for (pos, syms) <- byPos if pos.span.exists && ! syms.exists(_.hasAnnotation(defn.UnusedAnnot )) do
637642 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
639644 warnAt(pos)(UnusedSymbol .patVars)
640645 else if syms.exists(_.is(Mutable )) then // check unassigned var
641646 val sym = // recover the original
0 commit comments