New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scalac should not report warnings for macro generated AST #9852
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9852?orig=1 |
@som-snytt said: scala> def fImpl(c: Context) = { import c.universe._ ; q"{ 17 ; 42 }" }
fImpl: (c: scala.reflect.macros.blackbox.Context)c.universe.Tree
scala> def f: Int = macro fImpl
defined term macro f: Int
scala> f
<console>:17: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
f
^
res1: Int = 42
scala> def fImpl(c: Context): c.Tree = { import c.universe, universe._
| val g = universe.asInstanceOf[tools.nsc.Global]
| import tools.nsc.reporters._
| val r = new StoreReporter
| val saved = g.reporter
| try { g.reporter = r ; c.typecheck(q"{ 17 ; 42 }") } finally g.reporter = saved }
fImpl: (c: scala.reflect.macros.blackbox.Context)c.Tree
scala> def f: Int = macro fImpl
defined term macro f: Int
scala> f
res3: Int = 42
scala> :javap -pv -
[snip]
9: bipush 17
11: pop
12: bipush 42
14: putfield #26 // Field res3:I
17: return
|
@SethTisue said: |
How about I close this with the caveat that a handy reporter that makes it easy to suppress warnings would make my previous suggestion more refined? That could be done either globally or by the macro. The |
scala/scala#8995 improves the situation w/r/t to "a pure expression does nothing in statement position" warnings in particular |
I create some macros that may generate some warnings:
a pure expression does nothing in statement position; you may be omitting necessary parentheses
. I hope scalac could stop reporting these warnings.Warnings usually implies buggy hand-written code. Macro generated code does not fit that case at all.
The text was updated successfully, but these errors were encountered: