-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test for silent annotation with macros
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Test_2.scala:10: warning: a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses | ||
1 // warn | ||
^ | ||
Test_2.scala:19: warning: a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses | ||
1 // warn | ||
^ | ||
Test_2.scala:28: warning: a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses | ||
1 // warn | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
three warnings found | ||
one error found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import scala.reflect.macros.blackbox.Context | ||
|
||
object Macro { | ||
def discard(c: Context)(expr: c.Expr[Any]): c.Tree = { | ||
import c.universe._ | ||
q"()" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// scalac: -Werror | ||
|
||
import language.experimental.macros | ||
import scala.annotation.silent | ||
|
||
object Test { | ||
def discard(expr: Any): Unit = macro Macro.discard | ||
|
||
def t1a = discard { | ||
1 // warn | ||
2 | ||
} | ||
def t1b = discard { | ||
1: @silent | ||
2 | ||
} | ||
|
||
def t2a = discard { | ||
1 // warn | ||
2 | ||
} | ||
@silent def t2b = discard { | ||
1 | ||
2 | ||
} | ||
|
||
def t3a = discard { | ||
1 // warn | ||
2 | ||
} | ||
def t3b = discard { | ||
1 // warn | ||
2 | ||
}: @silent | ||
} |