Created
May 9, 2020 01:10
-
-
Save som-snytt/b0a447ccc4555a4947c0eab33948db39 to your computer and use it in GitHub Desktop.
post typer unit of work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package p | |
class Client { | |
def f = m.M.report("hello, world") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package m | |
import language.experimental.macros | |
import scala.reflect.macros.blackbox.Context | |
import scala.tools.nsc.Global | |
object M { | |
def report(s: String): Unit = macro Report.impl | |
} | |
object Report { | |
def impl(c: Context)(s: c.Expr[String]): c.Expr[Unit] = { | |
import c.universe._ | |
val global = c.universe.asInstanceOf[Global] | |
s.tree match { | |
case Literal(Constant(text: String)) => | |
c.enclosingUnit.asInstanceOf[global.CompilationUnit].toCheck += (() => println(s"*** $text ***")) | |
case t => c.abort(t.pos, "Not a literal") | |
} | |
c.Expr(Literal(Constant(()))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment