Skip to content
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

Closed
scabug opened this issue Jul 10, 2016 · 5 comments
Closed

scalac should not report warnings for macro generated AST #9852

scabug opened this issue Jul 10, 2016 · 5 comments
Labels

Comments

@scabug
Copy link

scabug commented Jul 10, 2016

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.

@scabug
Copy link
Author

scabug commented Jul 10, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9852?orig=1
Reporter: @Atry
See #9763, #8013

@scabug
Copy link
Author

scabug commented Jul 11, 2016

@som-snytt said:
The few macros I've produced have all been hand-written and buggy.

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

@scabug
Copy link
Author

scabug commented Aug 3, 2016

@SethTisue said:
I'm guessing this is a "wontfix", but maybe somebody else would like to weigh in.

@scabug scabug added the macros label Apr 7, 2017
@scabug scabug added this to the Backlog milestone Apr 7, 2017
@som-snytt
Copy link

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 -Xlint:unused warnings try to be sensitive as to whether linting before or after expansion is desired.

@SethTisue
Copy link
Member

scala/scala#8995 improves the situation w/r/t to "a pure expression does nothing in statement position" warnings in particular

@SethTisue SethTisue removed this from the Backlog milestone Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants