Open scabug opened 10 years ago
Imported From: https://issues.scala-lang.org/browse/SI-8077?orig=1 Reporter: @som-snytt Affected Versions: 2.11.0-M7
@xeno-by said: Could you provide a use case?
@som-snytt said: Sorry, I think my test was bad that day. In fact, I don't see the warnings.
Teo Klestrup Röijezon (teozkr) said: Running into this in a project of mine. It runs a block of statements, and replaces it with the REPL output. Using this triggers warnings for pure statements (like literals) in positions other than the last statement.
@xeno-by said: Even something as simple as this triggers the decribed issue:
import scala.reflect.macros.whitebox._
import scala.language.experimental.macros
object Macros {
def impl(c: Context)(x: c.Tree) = {
import c.universe._
q"()"
}
def foo(x: Any): Any = macro impl
}
object Test extends App {
Macros.foo {
1
2
}
}
@som-snytt said:
Thanks for reopening. I was faked out that day because the warning is emitted on { 2 == 1 }
but not on
{ val x = 1 ; 2 == x }
https://github.com/scala/scala/pull/8995 improves the situation w/r/t to "a pure expression does nothing in statement position" warnings in particular
It would be useful if macro invocations could get a free pass on warnings before expansion.
That way, a build can run with warnings turned high and fatal, even if a macro does something like turn "a pure expression [that] does nothing in statement position" into a productive member of society, for example, by wrapping a boolean in an assert.
Perhaps enable it with
-Ymacro-no-warn
, and perhaps try to buffer the warnings and emit them if there are warnings after expansion. (The old warnings may or may not be meaningful for a given macro.)