scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Nowarn for first typecheck of macro invocation #8077

Open scabug opened 10 years ago

scabug commented 10 years ago

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.)

scabug commented 10 years ago

Imported From: https://issues.scala-lang.org/browse/SI-8077?orig=1 Reporter: @som-snytt Affected Versions: 2.11.0-M7

scabug commented 10 years ago

@xeno-by said: Could you provide a use case?

scabug commented 10 years ago

@som-snytt said: Sorry, I think my test was bad that day. In fact, I don't see the warnings.

scabug commented 10 years ago

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.

Declaration Usage

scabug commented 10 years ago

@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
  }
}
scabug commented 10 years ago

@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 }
SethTisue commented 4 years ago

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