Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wire[ConcreteObjectExtendsTrait.ClassDefinedInTrait] is being treated as wire[Trait.ClassDefinedInTrait] #157

Open
richard-shurtz opened this issue Mar 2, 2021 · 0 comments

Comments

@richard-shurtz
Copy link

richard-shurtz commented Mar 2, 2021

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

@richard-shurtz richard-shurtz changed the title Incorrect type when wiring an inner class of an object Incorrect type returned from wire when wiring an inner class of an trait implemented by an object Mar 2, 2021
@richard-shurtz richard-shurtz changed the title Incorrect type returned from wire when wiring an inner class of an trait implemented by an object When wireing an inner class of an trait implemented by an object, wire is treating it as the trait's abstract type rather than the object's concrete type Mar 5, 2021
@richard-shurtz richard-shurtz changed the title When wireing an inner class of an trait implemented by an object, wire is treating it as the trait's abstract type rather than the object's concrete type wire[ConcreteObjectExtendsTrait.ClassDefinedInTrait] is being treated as wire[Trait.ClassDefinedInTrait] Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant