Skip to content

Instantly share code, notes, and snippets.

@clhodapp
Created August 23, 2016 02:15
Show Gist options
  • Save clhodapp/86ada22714c63f94e46759c7ad622a0e to your computer and use it in GitHub Desktop.
Save clhodapp/86ada22714c63f94e46759c7ad622a0e to your computer and use it in GitHub Desktop.
$ scala -language:_
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions for evaluation. Or try :help.
scala> import reflect.macros.whitebox.Context
import reflect.macros.whitebox.Context
scala> def idImpl(c: Context)(t: c.Tree): c.Tree = t
idImpl: (c: scala.reflect.macros.whitebox.Context)(t: c.Tree)c.Tree
scala> class C { def id(t: Int): Int = macro idImpl }
defined class C
scala> val c = new C
c: C = C@564718df
scala> val test = c: { def id(t: Int): Int }
test: AnyRef{def id(t: Int): Int} = C@564718df
scala> test.id(3)
java.lang.NoSuchMethodException: C.id(int)
at java.lang.Class.getMethod(Class.java:1786)
at .reflMethod$Method1(<console>:17)
... 32 elided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment