scodec/scodec — pull request #26 by stew (2014-09-29 13:30:34+00:00)
Title: remove the variance annotations on Encoder / Decoder

I realize this might be a controversial change. I don't know how widely people
are taking advantage of the variance on these types. We have found that the
variance can cause problems in implicit search. Here's a minimal example that
demonstrates some of the problems we have been having:

import scodec.{Decoder, Codec, codecs}
import scala.collection.immutable.{IndexedSeq}

object Foo {
// implicit val int32 = codecs.int32
implicit def indexedSeq[A:Codec]: Codec[IndexedSeq[A]] =
codecs.variableSizeBytes(codecs.int32, codecs.repeated(Codec[A]))
val x = implicitly[Decoder[IndexedSeq[Int]]]
}

When trying to compile this with variance in place, the error we get is:

diverging implicit expansion for type scodec.Decoder[scala.collection.immutable.IndexedSeq[Int]]

The implicit should not be found in this case because of the missing int32
implicit. With the variance annotations removed we correctly get an implicit
not found. While this is not the end of the world, we have more complex
examples where an implicit should be found, but the variance gets us diverging
implicits.