Skip to content

Instantly share code, notes, and snippets.

@echojc
Created October 16, 2015 09:53
Show Gist options
  • Save echojc/750ba177f88f4e81d2d0 to your computer and use it in GitHub Desktop.
Save echojc/750ba177f88f4e81d2d0 to your computer and use it in GitHub Desktop.
Using -Xprint:typer to see the result - looks like the typer is the one responsible for filling in implicits
/*
$ echo 'scalacOptions += "-Xprint:typer"' > build.sbt
$ sbt console
*/
// with the generic version
scala> class A { def foo[T](): String = ??? }
scala> implicit class PimpedA { def foo[T](i: String): String = ??? }
scala> val a = new A()
scala> a.foo("aoeu")
private[this] val res0: <error> = /*$line5.$read.$iw.$iw.*/a.foo[Nothing]("aoeu");
// with the non-generic version
scala> class B { def foo(): String = ??? }
scala> implicit class PimpedB { def foo(i: String): String = ??? }
scala> val b = new B()
scala> b.foo("aoeu")
private[this] val res1: String = /*$line8.$read.$iw.$iw.*/PimpedB(/*$line9.$read.$iw.$iw.*/b).foo("aoeu");
/*
It looks like the typer is the part of the compiler responsible for filling
in implicit conversions like this, and it's just not resolving when it's
the generic version.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment