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

Ambiguous implicit values for derived Show in 2.3.x #3720

Closed
tplaskowski opened this issue Dec 23, 2020 · 2 comments · Fixed by #3852
Closed

Ambiguous implicit values for derived Show in 2.3.x #3720

tplaskowski opened this issue Dec 23, 2020 · 2 comments · Fixed by #3852
Labels

Comments

@tplaskowski
Copy link

After instances for Seq was introduced in 2.3.0 code such

object test {

    import cats.Show
    import cats.syntax.all._

    final case class Foo(bar: String)

    implicit val showFoo = Show.fromToString[Foo]

    val foo = Foo("bar")

    show"$foo"

    val listFoo: List[Foo] = List(foo)

    show"$listFoo"
}

started to fail with, a rather unfriendly, error:

[error]  found   : List[test.Foo]
[error]  required: cats.Show.Shown
[error]     show"$listFoo"

The Shown derivation gives better error to understand what happened:

val shown  = cats.Show.Shown.mat(listFoo)
[error]  both method catsShowForList in object Show of type [A](implicit evidence$3: cats.Show[A]): cats.Show[List[A]]
[error]  and method catsShowForSeq in object Show of type [A](implicit evidence$4: cats.Show[A]): cats.Show[Seq[A]]
[error]  match expected type cats.Show.ContravariantShow[List[test.Foo]]
[error]     val shown: Show.Shown = cats.Show.Shown.mat(listFoo)

I suppose that this is because we need ContravatiantShow[-T] and you can easily fix the problem with importing the List instances. But it would be nice to either fix it somehow - maybe prioritise the Seq instances lower - or just drop a note in the release notes that you need to add import cats.instances.list._.

@djspiewak djspiewak added the bug label Dec 23, 2020
@djspiewak
Copy link
Member

This definitely seems like a rather serious oversight...

@tplaskowski
Copy link
Author

tplaskowski commented Dec 24, 2020

I've just checked that the code above compiles if I will change import cats.syntax.all._ to import cats.implicits._. It finds catsStdShowForList.
So maybe it wasn't caught because people are not migrated yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants