Skip to content

Commit

Permalink
#9944: upgrade SplainFormatting and relevant test partest to be on pa…
Browse files Browse the repository at this point in the history
…r with splain 1.0.0
  • Loading branch information
tribbloid committed Feb 14, 2023
1 parent c47f663 commit 7117ee4
Show file tree
Hide file tree
Showing 5 changed files with 435 additions and 100 deletions.
25 changes: 15 additions & 10 deletions src/compiler/scala/tools/nsc/typechecker/splain/SplainData.scala
Expand Up @@ -14,6 +14,7 @@ package scala.tools.nsc
package typechecker
package splain

import scala.annotation.tailrec
import scala.util.matching.Regex

trait SplainData {
Expand Down Expand Up @@ -68,10 +69,20 @@ trait SplainData {
}

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

@tailrec
private def unapplyRecursively(tree: Tree): Tree =
tree match {
case TypeApply(fun, _) => unapplyRecursively(fun)
case Apply(fun, _) => unapplyRecursively(fun)
case a => a
}

def cleanCandidate(e: ImplicitError): String =
unapplyCandidate(e).toString match {
case ImplicitError.candidateRegex(suf) => suf
case a => a
}

def candidateName(e: ImplicitError): String =
Expand All @@ -83,12 +94,6 @@ trait SplainData {

val candidateRegex: Regex = """.*\.this\.(.*)""".r

def cleanCandidate(e: ImplicitError): String =
unapplyCandidate(e).toString match {
case candidateRegex(suf) => suf
case a => a
}

def shortName(ident: String): String = ident.substring(ident.lastIndexOf(".") + 1)
}
}

0 comments on commit 7117ee4

Please sign in to comment.