Skip to content

Commit b1ea828

Browse files
lrytzdwijnand
authored andcommitted
Add @nowarn annotation for local warning suppression
Integrate the fantastic [silencer](https://github.com/ghik/silencer) compiler plugin by @ghik into the compiler, which allows suppressing warnings locally using he `@nowarn` annotation. The `@nowarn` annotation suppresses warnings within the scope covered by the annotation. - `@nowarn def foo = ...`, `@nowarn class C { ... }` suppress warnings in a definition - `expression: @nowarn` suppress warnings in a specific expression The annotation can be configured to filter selected warnings, for example `@nowarn("cat=deprecation")` only suppresses deprecation warnings. The filter configuration syntax is the same as in `-Wconf`. MiMa exception for addition of `scala.annotation.nowarn` Reporting warnings is now delayed until after typer, because the typer collects `@nowarn` annotations. If we stop before typer (e.g., because there are errors in the parser), all warnings are shown, even if they are enclosed in `@silent`. If a phase before typer has both errors and warnings, all errors are printed before the warnings. (cherry picked from commit 5a93cba)
1 parent 4c6c0d4 commit b1ea828

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala.annotation
14+
15+
/** An annotation for local warning suppression.
16+
*
17+
* The optional `value` parameter allows selectively silencing messages, see `scalac -Wconf:help`
18+
* for help. Examples:
19+
*
20+
* {{{
21+
* def f = {
22+
* 1: @nowarn // don't warn "a pure expression does nothing in statement position"
23+
* 2
24+
* }
25+
*
26+
* @nowarn def f = { 1; deprecated() } // don't warn
27+
*
28+
* @nowarn("msg=pure expression does nothing")
29+
* def f = { 1; deprecated() } // show deprecation warning
30+
* }}}
31+
*
32+
* To ensure that a `@nowarn` annotation actually suppresses a warning, enable `-Xlint:nowarn`.
33+
*/
34+
class nowarn(value: String = "") extends ClassfileAnnotation

0 commit comments

Comments
 (0)