@@ -2104,12 +2104,38 @@ class Typer extends Namer
2104
2104
lazy val annotCtx = annotContext(mdef, sym)
2105
2105
// necessary in order to mark the typed ahead annotations as definitely typed:
2106
2106
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)
2108
2111
}
2109
2112
2110
2113
def typedAnnotation (annot : untpd.Tree )(using Context ): Tree =
2111
2114
checkAnnotArgs(typed(annot, defn.AnnotationClass .typeRef))
2112
2115
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
+
2113
2139
def typedValDef (vdef : untpd.ValDef , sym : Symbol )(using Context ): Tree = {
2114
2140
val ValDef (name, tpt, _) = vdef
2115
2141
completeAnnotations(vdef, sym)
@@ -2505,6 +2531,8 @@ class Typer extends Namer
2505
2531
2506
2532
def typedAnnotated (tree : untpd.Annotated , pt : Type )(using Context ): Tree = {
2507
2533
val annot1 = typedExpr(tree.annot, defn.AnnotationClass .typeRef)
2534
+ if Annotations .annotClass(annot1) == defn.NowarnAnnot then
2535
+ registerNowarn(annot1, tree)
2508
2536
val arg1 = typed(tree.arg, pt)
2509
2537
if (ctx.mode is Mode .Type ) {
2510
2538
if arg1.isType then
0 commit comments