Bug 142
This proposal is somewhat related to original issue #142. It is described by following test-case:
class A()
class B(val oa: Option[A])
object TestSomeOption {
val a = new A()
val oa = Some(new A())
val b = wire[B]
}
object TestSomeValue {
val a = new A()
val b = wire[B]
}
object TestNone {
val b = wire[B]
}
require(TestSomeOption.b.oa.contains(TestSomeOption.oa.get))
require(TestSomeValue.b.oa.contains(TestSomeValue.a))
require(TestNone.b.oa.isEmpty)
- When a type to wire is
Option[A]and an instance ofOption[A]exists, it is wired as normal. - Otherwise if an instance
aof typeAexists, it is wired asSome(a). - Otherwise it is wired as
None.
Current change is not fully complete. In particular more test-cases would be required. It is more of a proof-of-concept. But I would appreciate any comments.
Hm, I'm not convinced. I'd be afraid that this might lead to confusing behavior, if a parameter is wired as None because it's missing for some possibly not-obvious reason.
What about a separate method e.g. wireOpt? Anyway, thanks for the review :)
Yes, wireOpt might make more sense - it explicitly states the intent. Though then, I would name it wireOption :)
One more detail: Currently the new feature allows for nesting: https://github.com/sijarsu/macwire/blob/bug-142/tests/src/test/resources/test-cases/_t142_nested.success). Would you like me to keep it that way? Or maybe limit it to just this case: https://github.com/sijarsu/macwire/blob/bug-142/tests/src/test/resources/test-cases/_t142.success
I think Option[Option[A]] is suspicious, so I'd keep it without nesting