Skip to content

Instantly share code, notes, and snippets.

@yanns
Created May 18, 2014 13:44
Show Gist options
  • Save yanns/b0af896bf342d07bb5c2 to your computer and use it in GitHub Desktop.
Save yanns/b0af896bf342d07bb5c2 to your computer and use it in GitHub Desktop.
expire with scala macros
scala> import scala.reflect.macros.blackbox.Context
import scala.reflect.macros.blackbox.Context
scala> def expire_impl(c: Context)(): c.Expr[Unit] = {
| c.error(c.enclosingPosition, "has expired")
| c.literalUnit
| }
<console>:10: warning: method literalUnit in trait ExprUtils is deprecated: Use quasiquotes instead
c.literalUnit
^
expire_impl: (c: scala.reflect.macros.blackbox.Context)()c.Expr[Unit]
scala> import scala.language.experimental.macros
import scala.language.experimental.macros
scala> def expire(): Unit = macro expire_impl
defined term macro expire: ()Unit
scala> expire()
<console>:12: error: has expired
expire()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment