Skip to content

Instantly share code, notes, and snippets.

@retronym
Created April 20, 2012 20:59
Show Gist options
  • Save retronym/2431859 to your computer and use it in GitHub Desktop.
Save retronym/2431859 to your computer and use it in GitHub Desktop.
unimplicitly
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]
^
@dcsobral
Copy link

You do know you can edit (and version) your gists, don't you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment