Hi!
We are upgrading from 0.11.7 to 0.12.x. After fixing the code after all API changes, I've run unit tests and suddenly some of them failed. Investigation showed possible regression in RM macros. This best illustrated by following test, that passed with RM version 0.11.7 and fails with version 0.12.1:
package test
import org.scalatest.{FunSuite, Matchers}
import reactivemongo.bson.{BSONDocument, Macros}
case class SocialLogin(id: String, name: String, friendsIds: Option[Seq[String]] = None)
object SocialLogin {
def apply(): SocialLogin = SocialLogin(id = "", name = "", friendsIds = None)
}
class ReactiveMongoMacrosWithApplyOverloadTest extends FunSuite with Matchers {
test("ReactiveMongo macros should ignore apply overload with different number of parameters") {
val v = SocialLogin("id", "name")
val handler = Macros.handler[SocialLogin]
handler.write(v) shouldBe BSONDocument("id" -> "id", "name" -> "name")
}
}
Further investigation showed that it is not just the empty-parameters "apply" that causes it - RM macros happily pick up any apply override where parameters types list is a prefix of unapply parameters types list. So in case of having:
case class SocialLogin(id: String, name: String, friendsIds: Seq[String])
object SocialLogin {
def apply(id: String, name: String): SocialLogin = SocialLogin(id, name, friendsIds = Seq.empty)
}
Macros pick up shorter apply and throw friendIds list out of the window. This breaks our code as we routinely use apply overload to provide handy shortcuts for most common initialization pattern, and is extremely hard to detect as there are no warnings of any kind and the tests usually work unless they specifically validate "rightmost" parameters.
Is this true regression or intended behavior?
_________
BR, Dmitry