`wire[ConcreteObjectExtendsTrait.ClassDefinedInTrait]` is being treated as `wire[Trait.ClassDefinedInTrait]`

未关闭
#157 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
scala
领域
tooling

调研方向

首先复现 issue 中的两个示例,并比较 wire 与所提供的 wireWith workaround 的行为。跟踪 wire 如何解析 ConcreteObject.Klass 及其依赖类型;当具体的嵌套类型得到保留,且两个示例都能在不使用 workaround 的情况下编译时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
Scala
星标
1.3k
派生
77
平均合并
9 分钟
30 天内合并 PR
4

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

softwaremill/macwire 的其他 Issue

查看 softwaremill/macwire 的全部 Issue

相似的 Issue

更多 Scala Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。