Search code examples
scalaakkamarshallingimplicit-conversionimplicit

In Scala how to find THE effective implicit methods, declarations and conversions during an execution


Trying to understand akka marshalling/unmarshalling and found a lot of scala implicit magic that goes on in the background and under the hood.

Question: Is there a way to find which implicit constructs are effective during an execution. Things that would be useful to know: - what implicit declarations and conversions are effective - where they are declared

What I'm thinking is an IDE plugin for this may be? To be used during code debug?

I think this would help in understanding akka marshalling/unmarshalling but also it would be useful generally wherever complex implicit features are used.


Solution

  • Implicits are selected at compile time.

    With -Xlog-implicit-conversions:

    scala 2.13.0-M5> "42".toInt
                     ^
                     applied implicit conversion from String("42") to ?{def toInt: ?} = implicit def augmentString(x: String): scala.collection.StringOps
    res0: Int = 42
    
    scala 2.13.0-M5> "42".toInt //print<TAB>
       scala.Predef.augmentString("42").toInt // : Int
    

    -Xlog-implicits explains when implicits do not apply.

    IntelliJ has "show implicits".