BSONWriter Covariance

13 views
Skip to first unread message

James Meyer

unread,
Mar 28, 2018, 3:19:27 AM3/28/18
to ReactiveMongo - http://reactivemongo.org
At the time of writing (ReactiveMongo version 0.13) the BSONWriter trait is defined as follows: (ref https://github.com/ReactiveMongo/ReactiveMongo/blob/26c322f9a0aec66725933052758ca712ed0f1cea/bson/src/main/scala/BSONWriter.scala#L8)

trait BSONWriter[T, B <: BSONValue] { ...

The type parameter B being invariant. What this means is you can't pass a BSONDocumentWriter[T] to a function expecting a BSONWriter[T, B],
even though the BSONDocument produced by the BSONDocumentWriter is obviously a subtype of a BSONValue.

Is there a specific reason why this type parameter is not covariant instead? i.e.

trait BSONWriter[T, +B <: BSONValue] { ...

-James





Reply all
Reply to author
Forward
0 new messages