Skip to content

Add more verbose mode for implicits #73

@tribbloid

Description

@tribbloid

I just come with the following observation when playing with it for different edge cases:

-Vimplicits-verbose-candidate

In the following example:

  trait F[I, O]

  trait G1[A, B]
  trait G2[A, B]

  implicit def f[I, M, O](
      implicit
      g1: G1[I, M],
      g2: G2[M, O]
  ): F[I, O] = ???

  implicit def g1: G1[Int, String] = ???

  implicitly[F[Int, Char]]

this trigger the error report:

newSource1.scala:26: error: implicit error;
!I e: F[Int, Char]
f invalid because:
!I g2: G2[M, Char]
  implicitly[F[Int, Char]]
            ^

Turns out that the default implementation of:

    def unapplyCandidate(e: ImplicitError): Tree =
      e.candidate match {
        case TypeApply(fun, _) => fun
        case a                 => a
      }

shrug off type signatures of f (it should be f[Int, String, Char]). debugging of this error becomes much harder, considering that the following line:

!I g2: G2[M, Char]

Shows only the unreified type signature, the reified version:

!I g2: G2[String, Char]

Cannot be found anywhere.

-Vimplicits-verbose-position

Since the parameter keepmodules is discarded in scala 2.13.6. Package or owner information won't be shown in the message. This means if we have multiple functions like f or g1 with similar signature, it will be difficult to determine which one is the real candidate.

This new option should display the line number for each candidate. Making it much harder to cause confusion, e.g. for the above example, the output may become:

newSource1.scala:26: error: implicit error;
!I e: F[Int, Char]
Annotation.f[Int, String, Char] invalid because ...... source-<toolbox>,line-18,offset=218
!I g2: G2[M, Char]
  implicitly[F[Int, Char]]
            ^

The source-<toolbox>,line-18,offset=218 is generated by candidate.symbol.pos.showDebug, obviously this format can be improved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions