Given search when reading the code

I apologise in advance if this has already been detailed elsewhere, but the given/implicits debate is so widespread that it’s hard to nitpick the needed information.
Please refer me to the relevant post as needed.

I’ve read that the new compiler will be much more friendly regarding given instances, both when there are errors in missing instances in scope and suggesting possibly useful imports.

I wondered if there is something to ease up navigation of the code when there is no error.
It was pointed out to me and I guess it’s a shared opinion among people unfamiliar with the implicit mechanics, that in scala2 one of the hurdles is how to trace the actual implicits used at call site (talking about implicit params), and what imports actually bring those in scope.

Intellij provides such hints, but not everyone should rely necessarily on a specific feature of a specific editor/IDE. And much more when exploring or reviewing some code, you might be working from a web page, like a git cloud solution.

Does the current dotty version provide hints in some form?
Did someone raise the issue before? Has it being considered from SIP members?

Thank you

1 Like

Hello, if you have an example like the following:

object Demo extends App:
  val numbers = List(8,3,5,7,0).sorted
  println(numbers)

and compile it with dotc Demo.scala
then you can use dotc -decompile Demo and you will see which implicits were inserted (in this case scala.math.Ordering.Int was inserted to the sorted method call):

/** Decompiled from ./Demo.tasty */
@scala.annotation.internal.SourceFile("example.scala") object Demo extends scala.App {
  val numbers: scala.collection.immutable.List[scala.Int] = scala.List.apply[scala.Int](8, 3, 5, 7, 0).sorted[scala.Int](scala.math.Ordering.Int)
  scala.Predef.println(Demo.numbers)
}

There is also help for inserting implicits that can not be found: https://www.scala-lang.org/blog/2020/05/05/scala-3-import-suggestions.html

3 Likes