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

Đang mở
#157 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
scala
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện cả hai ví dụ trong issue và so sánh hành vi của wire với workaround wireWith được cung cấp. Theo dõi cách wire phân giải ConcreteObject.Klass và các kiểu phụ thuộc của nó; công việc được hoàn tất khi các kiểu lồng nhau cụ thể được giữ nguyên và cả hai ví dụ đều biên dịch mà không cần workaround.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Scala
Star
1.3k
Fork
77
Merge trung bình
9 phút
Pull request đã merge (30 ngày)
4

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của softwaremill/macwire

Tất cả issue của softwaremill/macwire

Issue tương tự

Thêm issue về Scala

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.