Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support macro annotation expansions in -Wmacros:MODE
Specifically, for `-Wmacros:none` or `-Wmacros:before`, we shouldn't warn about unused symbols in code resulting from expansion of a macro annotation.
- Loading branch information
Showing
6 changed files
with
68 additions
and
2 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
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,6 @@ | ||
Test_2.scala:2: warning: parameter value x in anonymous function is never used | ||
@mymacro | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
1 warning | ||
1 error |
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,22 @@ | ||
// scalac: -Ymacro-annotations | ||
import scala.language.experimental.macros | ||
import scala.reflect.macros.blackbox.Context | ||
import scala.annotation.StaticAnnotation | ||
|
||
object Macros { | ||
def annotImpl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { | ||
import c.universe._ | ||
val classTree = annottees.head.tree | ||
val objectTree = q""" | ||
object X { | ||
def f: Int => String = { x => "hello" } | ||
} | ||
""" | ||
|
||
c.Expr[Any](Block(List(classTree, objectTree), Literal(Constant(())))) | ||
} | ||
} | ||
|
||
class mymacro extends StaticAnnotation { | ||
def macroTransform(annottees: Any*): Any = macro Macros.annotImpl | ||
} |
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,7 @@ | ||
// scalac: -Ymacro-annotations -Wunused:params -Wmacros:after -Werror | ||
@mymacro | ||
class X | ||
|
||
object Test { | ||
println(X.f(123)) | ||
} |
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,22 @@ | ||
// scalac: -Ymacro-annotations | ||
import scala.language.experimental.macros | ||
import scala.reflect.macros.blackbox.Context | ||
import scala.annotation.StaticAnnotation | ||
|
||
object Macros { | ||
def annotImpl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { | ||
import c.universe._ | ||
val classTree = annottees.head.tree | ||
val objectTree = q""" | ||
object X { | ||
def f: Int => String = { x => "hello" } | ||
} | ||
""" | ||
|
||
c.Expr[Any](Block(List(classTree, objectTree), Literal(Constant(())))) | ||
} | ||
} | ||
|
||
class mymacro extends StaticAnnotation { | ||
def macroTransform(annottees: Any*): Any = macro Macros.annotImpl | ||
} |
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,7 @@ | ||
// scalac: -Ymacro-annotations -Wunused:params -Werror | ||
@mymacro | ||
class X | ||
|
||
object Test { | ||
println(X.f(123)) | ||
} |