Skip to content

Macro with Unit type splicing non Unit fails with splice outside quotes #3912

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

Closed
nicolasstucki opened this issue Jan 25, 2018 · 6 comments
Closed

Comments

@nicolasstucki
Copy link
Contributor

import scala.quoted._
object Macros {
  inline def foo(): Unit = ~impl()
  def impl(): Expr[Int] = '(1)
}
import scala.quoted._
import Macros._
class Test {
  val a: Unit = foo()
}

fails with

5 |    ~impl()
  |    ^^^^^^^
  |    splice outside quotes

because inline def foo(): Unit = ~impl() is transformed to
inline def foo(): Unit = { ~impl(); () }, which is correct.

We need a better error message for this.

@nicolasstucki
Copy link
Contributor Author

This should probably be done in ReifyQuotes.

@odersky
Copy link
Contributor

odersky commented Feb 1, 2018

Why is this not expanded to a macro?

@nicolasstucki
Copy link
Contributor Author

We could expand it to a macro. We would need to not insert the explicit () or to recognise that shape of tree as a macro body.

@biboudis
Copy link
Contributor

biboudis commented Feb 4, 2018

Where is it best to transform the shape of the tree? In transform of ReifyQuotes right (link)?

@nicolasstucki
Copy link
Contributor Author

nicolasstucki commented Feb 4, 2018

Not sure, maybe it should be before. We should probably have it marked as a macro before that to make it take this branch Yes, the issue is probably there.

@nicolasstucki
Copy link
Contributor Author

nicolasstucki commented Feb 15, 2018

The following macro has a similar issue

import scala.quoted._
object Macros {
  inline def foo(): Int = { ~impl() }
  def impl(): Expr[Int] = '(1)
}
import scala.quoted._
import Macros._
class Test {
  val a: Unit = foo()
}

In both cases the code that is splices is found in a block as statement or expression position. We probably handle these as part of the Inlined branch conditions.

biboudis added a commit to dotty-staging/dotty that referenced this issue Feb 19, 2018
nicolasstucki added a commit that referenced this issue Feb 21, 2018
Fix #3912: Account for units and blocks in inline and macros
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants