From 2091960e8bb4650f213d7dc5445c7c5fc34c50c9 Mon Sep 17 00:00:00 2001 From: Cody Allen Date: Sat, 16 Jul 2016 12:26:52 -0400 Subject: [PATCH] Add a note about issues with Functor.widen This is a followup on [this discussion](https://github.com/typelevel/cats/issues/1080#issuecomment-225892635). --- core/src/main/scala/cats/Functor.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/cats/Functor.scala b/core/src/main/scala/cats/Functor.scala index 1099181196..1da9494a39 100644 --- a/core/src/main/scala/cats/Functor.scala +++ b/core/src/main/scala/cats/Functor.scala @@ -20,7 +20,14 @@ import simulacrum.typeclass /** * Lifts natural subtyping covariance of covariant Functors. - * could be implemented as map(identity), but the Functor laws say this is equivalent + * + * NOTE: In certain (perhaps contrived) situations that rely on universal + * equality this can result in a `ClassCastException`, because it is + * implemented as a type cast. It could be implemented as `map(identity)`, but + * according to the functor laws, that should be equal to `fa`, and a type + * cast is often much more performant. + * See [[https://github.com/typelevel/cats/issues/1080#issuecomment-225892635 this example]] + * of `widen` creating a `ClassCastException`. */ def widen[A, B >: A](fa: F[A]): F[B] = fa.asInstanceOf[F[B]]