Find all implicits

后端 未结 2 766
孤独总比滥情好
孤独总比滥情好 2020-12-16 13:38

Is there a way in Scala to find and display all uses of implicits in my code, or compile without implicits enabled (so I get compilation errors)? I\'m hoping to identify pla

相关标签:
2条回答
  • 2020-12-16 14:00

    You can use -Xprint:typer option and look at how the inner loops of interest are typed checked. The implicit calls will appear in the printed source code. You may need to pipe the output to a file so that you can search for the interesting sections.

    Also the Scala Eclipse IDE nightlies at http://scala-ide.org/download/nightly.html have a display implicit feature. You have to enable it in the Preferences, Scala, Implicits section.

    The double arrows on the left margin shows that an implicit is used:

    enter image description here

    On hover, it shows the details:

    enter image description here

    The IDEA scala plugin can also show implicit conversions with underline, see the same piece of code:

    enter image description here

    It should also show which one is used using the CTRL-SHIFT-Q shortcut, but I had less success with it...

    0 讨论(0)
  • 2020-12-16 14:21

    As of yesterday (it's just a coincidence) there is -Xlog-implicit-conversions.

    scalac -Xlog-implicit-conversions -d /tmp /scala/trunk/src/library/scala/util/Random.scala 
    /scala/trunk/src/library/scala/util/Random.scala:115: applied implicit conversion from Int to ?{val to: ?} = implicit def intWrapper(x: Int): scala.runtime.RichInt
        for (n <- buf.length to 2 by -1) {
                      ^
    
    0 讨论(0)
提交回复
热议问题