scala-with-cats icon indicating copy to clipboard operation
scala-with-cats copied to clipboard

Printable Library part 3: Extension method `format` conflicts with `StringLike.format`

Open hseeberger opened this issue 7 years ago • 1 comments

  implicit val catPrintable: Printable[Cat] =
    (cat: Cat) => {
      import PrintableInstances._
      import PrintableSyntax._
      val name  = cat.name.format // compiler error on String
      val age   = cat.age.format // works fine on Int
      val color = cat.color.format // compiler error on String
      s"$name is a $age year-old $color cat"
    }

I suggest to rename format to fmt to avoid the conflict.

hseeberger avatar Nov 28 '17 10:11 hseeberger

Ah. That old chestnut. Thanks for the heads up. I’m travelling this week but will take a look next week.

Cheers, Dave On Tue, 28 Nov 2017 at 11:29, Heiko Seeberger [email protected] wrote:

implicit val catPrintable: Printable[Cat] = (cat: Cat) => { import PrintableInstances._ import PrintableSyntax._ val name = cat.name.format // compiler error on String val age = cat.age.format // works fine on Int val color = cat.color.format // compiler error on String s"$name is a $age year-old $color cat" }

I suggest to rename format to fmt to avoid the conflict.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/underscoreio/advanced-scala/issues/99, or mute the thread https://github.com/notifications/unsubscribe-auth/AAOI55wGb9nSzW1JTwvDDM2PaIe48jU_ks5s6-CYgaJpZM4QtAo0 .

davegurnell avatar Nov 28 '17 18:11 davegurnell

This is fixed, a mere 7 years after it was reported! I use display and print as the method names.

noelwelsh avatar Jun 13 '24 10:06 noelwelsh