softwaremill / softwaremill/macwire

Feature request: wiring abstract classes and traits

Open
#133 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
1.3k
Forks
77
Avg merge
9m
Merged PRs (30d)
4

Description

The following does not compile:

object Foo {
  trait Dep
  abstract class Abs {
    def foo: Dep
  }
  trait T {
    def bar: Dep
  }

  val d: Dep = new Dep {}

  val a: Abs = wire[Abs]
  val t: T = wire[T]

  def main(args: Array[String]): Unit =
    println(s"a.foo ${a.foo}")
}

MacWire says

Error: class Abs is abstract; cannot be instantiated
  val a: Abs = wire[Abs]
Error: Cannot find a public constructor nor a companion object for [Foo.T]
  val t: T = wire[T]

It would be nice if macwire could wire abstract classes and traits when it can satisfy abstract members like it does for constructor args.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Scala reproduction in the issue and inspect how macwire currently handles constructor arguments, abstract classes, and traits. Define completion as making both wire[Abs] and wire[T] compile when their abstract members can be satisfied, while preserving the existing error behavior when they cannot.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.