Created
April 20, 2012 20:59
-
-
Save retronym/2431859 to your computer and use it in GitHub Desktop.
unimplicitly
This file contains hidden or 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
scala> import scala.language.experimental.macros | |
import scala.language.experimental.macros | |
scala> def unimplicitlyImpl[A: c.TypeTag](c: reflect.makro.Context) = { | |
| val A = implicitly[c.TypeTag[A]].tpe | |
| val i = c.inferImplicitValue(A, silent = true) | |
| if (i == c.mirror.EmptyTree) c.reify(()) | |
| else sys.error("unexpected implicit of type %s: %s".format(A, i)) | |
| } | |
unimplicitlyImpl: [A](c: scala.reflect.makro.Context)(implicit evidence$1: c.TypeTag[A])c.mirror.Expr[Unit] | |
scala> def unimplicitly[A] = macro unimplicitlyImpl[A] | |
unimplicitly: [A]=> Unit | |
scala> unimplicitly[String] | |
scala> unimplicitly[Int => Int] | |
<console>:11: error: exception during macro expansion: | |
java.lang.RuntimeException: unexpected implicit of type Int => Int: scala.this.Predef.conforms[Int] | |
at scala.sys.package$.error(package.scala:27) | |
at .m(<console>:11) | |
unimplicitly[Int => Int] | |
^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You do know you can edit (and version) your gists, don't you?