Skip to content

Commit

Permalink
Implicitly use Show[Expectation]
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek committed Nov 14, 2024
1 parent 8b5c967 commit 351645d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/shared/src/main/scala/cats/parse/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -974,13 +974,13 @@ object Parser {
def unapply(error: Error): Option[(Int, NonEmptyList[Expectation])] =
Some((error.failedAtOffset, error.expected))

implicit val catsShowError: Show[Error] =
implicit def catsShowErrorGivenExpectation(implicit showExp: Show[Expectation]): Show[Error] =
new Show[Error] {
def show(error: Error): String = {
val nl = "\n"

def errorMsg = {
val expectations = error.expected.toList.iterator.map(e => s"* ${e.show}").mkString(nl)
val expectations = error.expected.toList.iterator.map(e => s"* ${showExp.show(e)}").mkString(nl)

s"""|expectation${if (error.expected.tail.nonEmpty) "s" else ""}:
|$expectations""".stripMargin
Expand Down Expand Up @@ -1037,6 +1037,9 @@ object Parser {
}
}
}

// This is here for binary compatibility, but no longer implicit
val catsShowError: Show[Error] = catsShowErrorGivenExpectation(Expectation.catsShowExpectation)
}

/** Enables syntax to access product01, product and flatMap01 This helps us build Parser instances
Expand Down

0 comments on commit 351645d

Please sign in to comment.