Skip to content

Commit b0e843b

Browse files
authored
Merge pull request #7108 from dotty-staging/fix-#7082
Fix #7082: Refine overloading resolution with default arguments
2 parents 6d16b93 + 6805c39 commit b0e843b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,11 +1721,15 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
17211721
.map(advanced.toMap) // map surviving result(s) back to original candidates
17221722
case _ =>
17231723
val noDefaults = alts.filter(!_.symbol.hasDefaultParams)
1724-
if (noDefaults.length == 1) noDefaults // return unique alternative without default parameters if it exists
1724+
val noDefaultsCount = noDefaults.length
1725+
if (noDefaultsCount == 1)
1726+
noDefaults // return unique alternative without default parameters if it exists
1727+
else if (noDefaultsCount > 1 && noDefaultsCount < alts.length)
1728+
resolveOverloaded(noDefaults, pt, targs) // try again, dropping defult arguments
17251729
else {
17261730
val deepPt = pt.deepenProto
17271731
if (deepPt ne pt) resolveOverloaded(alts, deepPt, targs)
1728-
else alts
1732+
else candidates
17291733
}
17301734
}
17311735
}

tests/pos/i7082.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object Overloads {
2+
3+
def foo[V](x: Int = 0, y: Int = 0, z: Int = 0): Nothing = ???
4+
5+
def foo[V](x: Int, y: Int): Nothing = ???
6+
7+
def foo[V](x: Int): Nothing = ???
8+
9+
foo(1)
10+
11+
}

0 commit comments

Comments
 (0)