Skip to content

Commit

Permalink
workaround for a possible scala bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kailuowang committed Aug 8, 2017
1 parent 272c684 commit fdcd48f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 3 additions & 2 deletions core/src/main/scala/cats/Show.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import cats.functor.Contravariant
@typeclass trait Show[T] extends Show.ContravariantShow[T] {
// duplicated so simulacrum knows it requires an instance of this trait
def show(t: T): String
def _show(t: T): String = show(t)
}

object Show {
trait ContravariantShow[-T] {
def show(t: T): String
def _show(t: T): String
}

/** creates an instance of [[Show]] using the provided function */
Expand All @@ -32,7 +33,7 @@ object Show {

final case class Shown(override val toString: String) extends AnyVal
object Shown {
implicit def mat[A](x: A)(implicit z: ContravariantShow[A]): Shown = Shown(z show x)
implicit def mat[A](x: A)(implicit z: ContravariantShow[A]): Shown = Shown(z _show x)
}

final case class ShowInterpolator(_sc: StringContext) extends AnyVal {
Expand Down
17 changes: 16 additions & 1 deletion tests/src/test/scala/cats/tests/RegressionTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tests
import cats.data.{Const, NonEmptyList}

import scala.collection.mutable

import RegressionTests._
class RegressionTests extends CatsSuite {

// toy state class
Expand Down Expand Up @@ -123,4 +123,19 @@ class RegressionTests extends CatsSuite {
NonEmptyList.of(6,7,8).traverse_(validate) should === (Either.left("6 is greater than 5"))
checkAndResetCount(1)
}

test("#1802 duplicated method name") {
Show[First[String]]
}
}


object RegressionTests {
final case class First[A](getFirst: A) extends AnyVal
object First {
implicit def showInstance[A](implicit ev: Show[A]): Show[First[A]] = new Show[First[A]] {
override def show(f: First[A]): String = s"First(${ev.show(f.getFirst)})"
}
}

}

0 comments on commit fdcd48f

Please sign in to comment.