macwire icon indicating copy to clipboard operation
macwire copied to clipboard

Bug 142

Open mkrzemien opened this issue 4 years ago • 5 comments

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 of Option[A] exists, it is wired as normal.
  • Otherwise if an instance a of type A exists, it is wired as Some(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.

mkrzemien avatar May 24 '20 18:05 mkrzemien

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.

adamw avatar Jun 04 '20 10:06 adamw

What about a separate method e.g. wireOpt? Anyway, thanks for the review :)

mkrzemien avatar Jun 04 '20 10:06 mkrzemien

Yes, wireOpt might make more sense - it explicitly states the intent. Though then, I would name it wireOption :)

adamw avatar Jun 04 '20 11:06 adamw

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

mkrzemien avatar Jun 04 '20 16:06 mkrzemien

I think Option[Option[A]] is suspicious, so I'd keep it without nesting

adamw avatar Jun 05 '20 08:06 adamw