softwaremill / softwaremill/macwire
wrong constructor is being picked up
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 1.3k
- Forks
- 77
- Avg merge
- 9m
- Merged PRs (30d)
- 4
Description
In below code I am trying to construct Target object. Target class has 3 constructors but only one is preffered (the one annotated). This results in compilation error because wire[Target] picks up wrong constructor. I've intentionally provided to much eligible values here in order to show the naughty behaviour:
trait A
trait B
trait C
class Target(a: A) {
def this(b: B) = this(new A{})
@javax.inject.Inject
def this(c: C) = this(new A{})
}
val a: A = new A {}
val a1: A = new A {}
val b: B = new B {}
val b1: B = new B {}
val c = new C {}
val sa = wire[Target]
Error:(24, 16) Found multiple values of type [com.softwaremill.macwire.macwireakka.Demo.A]: [List(a, a1)]
val sa = wire[Target]
Error:(24, 16) ambiguous reference to overloaded definition,
both constructor Target in class Target of type (c: com.softwaremill.macwire.macwireakka.Demo.C)com.softwaremill.macwire.macwireakka.Demo.Target
and constructor Target in class Target of type (b: com.softwaremill.macwire.macwireakka.Demo.B)com.softwaremill.macwire.macwireakka.Demo.Target
match argument types (Null) and expected result type com.softwaremill.macwire.macwireakka.Demo.Target
val sa = wire[Target]
However if you provide type after sa:
val sa: Target = wire[Target]
it works fine.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided Scala reproduction and the wire[Target] entry point, then compare constructor selection with and without the explicit Target result type. The issue is resolved when the annotated constructor is selected without requiring val sa: Target and the reproduction no longer produces the ambiguity errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100