@@ -2104,12 +2104,38 @@ class Typer extends Namer
21042104 lazy val annotCtx = annotContext(mdef, sym)
21052105 // necessary in order to mark the typed ahead annotations as definitely typed:
21062106 for (annot <- mdef.mods.annotations)
2107- checkAnnotApplicable(typedAnnotation(annot)(using annotCtx), sym)
2107+ val annot1 = typedAnnotation(annot)(using annotCtx)
2108+ checkAnnotApplicable(annot1, sym)
2109+ if (Annotations .annotClass(annot1) == defn.NowarnAnnot )
2110+ registerNowarn(annot1, mdef)
21082111 }
21092112
21102113 def typedAnnotation (annot : untpd.Tree )(using Context ): Tree =
21112114 checkAnnotArgs(typed(annot, defn.AnnotationClass .typeRef))
21122115
2116+ def registerNowarn (tree : Tree , mdef : untpd.Tree )(using Context ): Unit =
2117+ val annot = Annotations .Annotation (tree)
2118+ def argPos = annot.argument(0 ).getOrElse(tree).sourcePos
2119+ val filters =
2120+ if annot.arguments.isEmpty then List (MessageFilter .Any )
2121+ else annot.argumentConstantString(0 ) match {
2122+ case None => annot.argument(0 ) match {
2123+ case Some (t : Select ) if t.name.toString == " $lessinit$greater$default$1" => List (MessageFilter .Any )
2124+ case _ =>
2125+ report.warning(s " filter needs to be a compile-time constant string " , argPos)
2126+ Nil
2127+ }
2128+ case Some (s) =>
2129+ if s.isEmpty then Nil
2130+ else
2131+ val (ms, fs) = s.split('&' ).map(WConf .parseFilter).toList.partitionMap(identity)
2132+ if (ms.nonEmpty)
2133+ report.warning(s " Invalid message filter \n ${ms.mkString(" \n " )}" , argPos)
2134+ fs
2135+ }
2136+ val range = mdef.sourcePos
2137+ ctx.run.suppressions.addSuppression(Suppression (tree.sourcePos, filters, range.start, range.end))
2138+
21132139 def typedValDef (vdef : untpd.ValDef , sym : Symbol )(using Context ): Tree = {
21142140 val ValDef (name, tpt, _) = vdef
21152141 completeAnnotations(vdef, sym)
@@ -2505,6 +2531,8 @@ class Typer extends Namer
25052531
25062532 def typedAnnotated (tree : untpd.Annotated , pt : Type )(using Context ): Tree = {
25072533 val annot1 = typedExpr(tree.annot, defn.AnnotationClass .typeRef)
2534+ if Annotations .annotClass(annot1) == defn.NowarnAnnot then
2535+ registerNowarn(annot1, tree)
25082536 val arg1 = typed(tree.arg, pt)
25092537 if (ctx.mode is Mode .Type ) {
25102538 if arg1.isType then
0 commit comments