0.12.2 Macros regression for sealed traits?

26 views
Skip to first unread message

Jean-Baptiste Giraudeau

unread,
Apr 19, 2017, 4:41:06 AM4/19/17
to ReactiveMongo - http://reactivemongo.org
Hi,

trying out the fresh 0.12.2 release this morning I found that some code does not compile anymore:

sealed trait TestEvent
case class Event1(test: String) extends TestEvent
case class Event2(test: String) extends TestEvent

object TestEvent {
  //implicit val event1Codec    = Macros.handler[Event1]
  //implicit val event2Codec    = Macros.handler[Event2]
  implicit val testEventCodec = Macros.handlerOpts[TestEvent, Macros.Options.SaveSimpleName]
}


gives

[error]   Implicit not found for 'Event1': reactivemongo.bson.BSONReader[_, com.lodh.loim.core.repository.mongo.Event1]
[error]   implicit val testEventCodec = Macros.
handlerOpts[TestEvent, Macros.Options.SaveSimpleName]

It works again if I uncomment the two implicits for the implementing case classes, but this was not necessary with 0.12.1.

Is the new behavior wanted for some reason? Can I change something to get back the old behavior?


-
jb


Cédric Chantepie

unread,
Apr 19, 2017, 8:57:43 AM4/19/17
to ReactiveMongo - http://reactivemongo.org
Rather than a regression I would call it an undocumented feature, even if I agree that's a change.

The macro behaviour was previously automatically materializing handler for subtypes of a sealed trait (if possible), which could lead in some case to recursion issue at compile time, so that's no longer the default behaviour.

If you are sure there is no implicit recursion, you can enable it using the MacroOptions.AutomaticMaterialization , as documented.

Jean-Baptiste Giraudeau

unread,
Apr 19, 2017, 9:06:30 AM4/19/17
to ReactiveMongo - http://reactivemongo.org
I see, thanks!
Reply all
Reply to author
Forward
0 new messages