macwire
macwire copied to clipboard
`wire[ConcreteObjectExtendsTrait.ClassDefinedInTrait]` is being treated as `wire[Trait.ClassDefinedInTrait]`
trait ObjectMixIn {
class Klass()
}
object ConcreteObject extends ObjectMixIn
class App {
lazy val klass: ConcreteObject.Klass = wire[ConcreteObject.Klass]
}
Fails compilation with
Error:(10, 46) type mismatch;
found : ObjectMixIn.this.Klass
required: ConcreteObject.Klass
lazy val klass: ConcreteObject.Klass = wire[ConcreteObject.Klass]
The macro is returning the (abstract) ObjectMixIn.this.Klasss type rather than the concrete ConcreteObject.Klass
And
trait ObjectMixIn {
class Depedency
class Klass(depedency: Depedency)
}
object ConcreteObject extends ObjectMixIn
class App {
lazy val depedency: ConcreteObject.Depedency = new ConcreteObject.Depedency
lazy val klass = wire[ConcreteObject.Klass]
}
Fails compilation with
Error:(12, 24) Cannot find a value of type: [ObjectMixIn.this.Depedency]
lazy val klass = wire[ConcreteObject.Klass]
So, in this case, it appears that wire is looking for as ObjectMixIn.this.Depedency rather than ConcreteObject.Dependency (and thus isn't finding it)
Described in the general case, it appears that wire[ConcreteObjectExtendsTrait.ClassDefinedInTrait] is being treated as wire[Trait.ClassDefinedInTrait]
My current workaround is to use wireWith, which seems to pull in the full, concrete-type correctly
trait ObjectMixIn {
class Klass()
object Klass {
def apply() = new Klass()
}
}
object ConcreteObject extends ObjectMixIn
class App {
lazy val klass: ConcreteObject.Klass = wireWith(ConcreteObject.Klass.apply _)
}
Thankfully, this works without adding too much boilerplate