Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not possible to provide own Show[Expectation] without Show[Error] #607

Open
DLakomy opened this issue Aug 31, 2024 · 1 comment · May be fixed by #624
Open

Not possible to provide own Show[Expectation] without Show[Error] #607

DLakomy opened this issue Aug 31, 2024 · 1 comment · May be fixed by #624

Comments

@DLakomy
Copy link

DLakomy commented Aug 31, 2024

Recently I've needed to provide my own Show[Expectation] but wanted to keep Show[Error] as is. It turns out it's not possible, as the latter doesn't take Show[Expectation] as a parameter. Example code (runnable via scala-cli):

//> using dep "org.typelevel::cats-parse:1.0.0"
//> using scala 2.13

import cats.parse.Parser
import cats.parse.Parser.{Error, Expectation}

import cats.Show
import cats.syntax.show._

val parseError: Error = Parser.string("something").parseAll("smth").swap.toOption.get

implicit val showExpectation: Show[Expectation] =
  new Show[Expectation] {
    override def show(exp: Expectation) = "myImpl"
  }

println(show"$parseError")

/* prints this (showExpectation is apparently ignored):

  smth
  ^
  expectation:
  * must match string: "something"

*/

It appears to be necessary to copy Show[Error] verbatim if one wants to customise how the expectations are rendered.

I think it wouldn't be necessary if this definition:

implicit val catsShowError: Show[Error] =

were changed to

implicit def catsShowError(implicit showExpectation: Show[Expectation]): Show[Error] =

To be honest I know my use case is very, very niche, but I thought I'd share this suggestion in case it appears useful. On the other hand, if the suggestion is wrong for some reason, I'll be happy to learn

@johnynek
Copy link
Collaborator

I think we can fix this without breaking binary compatibility. I’ll look at that.

@johnynek johnynek linked a pull request Nov 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@johnynek @DLakomy and others