Skip to content

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

@tplaskowski

Description

@tplaskowski

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._.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions