Possible macros regression in 0.12.x?

21 views
Skip to first unread message

Dmitry Mikhaylov

unread,
Apr 11, 2017, 4:36:58 AM4/11/17
to ReactiveMongo - http://reactivemongo.org
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

Dmitry Mikhaylov

unread,
Apr 11, 2017, 4:47:40 AM4/11/17
to ReactiveMongo - http://reactivemongo.org
Just in case this is a regression, here is suggested fix and tests.

Cédric Chantepie

unread,
Apr 12, 2017, 7:39:39 AM4/12/17
to ReactiveMongo - http://reactivemongo.org
Pull request is being validated. CLA would be required: https://github.com/ReactiveMongo/ReactiveMongo/pull/646
Reply all
Reply to author
Forward
0 new messages