macwire icon indicating copy to clipboard operation
macwire copied to clipboard

MacWire doesn't consider by-name params to be candidates for wiring

Open clhodapp opened this issue 8 years ago • 0 comments

First, a REPL transcript:

Welcome to Scala 2.12.1 (OpenJDK 64-Bit Server VM, Java 1.8.0_121).
Type in expressions for evaluation. Or try :help.

scala> import com.softwaremill.macwire.wire
import com.softwaremill.macwire.wire

scala> class IntWrapper(i: Int)
defined class IntWrapper

scala> def a(i: Int) = wire[IntWrapper]
a: (i: Int)IntWrapper

scala> def b(i: => Int) = wire[IntWrapper]
<console>:13: error: Cannot find a value of type: [Int]
       def b(i: => Int) = wire[IntWrapper]
                              ^

Long story short, I believe that the second example really should work as a convenient way of doing doing wiring for only-sometimes-needed dependencies. As it stands, the use-case can be accomplished with a workaround by declaring lazy val references inside of the block, but that's pretty ugly and repetitive.

clhodapp avatar May 01 '17 21:05 clhodapp