`wire[ConcreteObjectExtendsTrait.ClassDefinedInTrait]` is being treated as `wire[Trait.ClassDefinedInTrait]`
还没有人认领这个 Issue。
评估
调研方向
首先复现 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
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
softwaremill/macwire 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 35/100
softwaremill/macwire#412 · 3 条评论 ·
-
难度 4/5 3-5 天 新手友好度 25/100
softwaremill/macwire#391 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 20/100
softwaremill/macwire#301 · 2 条评论 ·
-
难度 5/5 一周以上 新手友好度 20/100
softwaremill/macwire#281 · 5 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
softwaremill/macwire#278 · 3 条评论 ·
查看 softwaremill/macwire 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
ergoplatform/ergodocs#614 ·
-
area:ci enhancement requires-triage
难度 2/5 1-3 小时 新手友好度 84/100
apache/datafusion-comet#6078 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
-
[VL] madvise(WILLNEED) call fails in MmapFileStream because of wrong calculation of fetching length 未关闭bug triage
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 76/100
chipsalliance/rocket-chip#3831 ·