Skip to content

Fix #7082: Refine overloading resolution with default arguments #7108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1721,11 +1721,15 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
.map(advanced.toMap) // map surviving result(s) back to original candidates
case _ =>
val noDefaults = alts.filter(!_.symbol.hasDefaultParams)
if (noDefaults.length == 1) noDefaults // return unique alternative without default parameters if it exists
val noDefaultsCount = noDefaults.length
if (noDefaultsCount == 1)
noDefaults // return unique alternative without default parameters if it exists
else if (noDefaultsCount > 1 && noDefaultsCount < alts.length)
resolveOverloaded(noDefaults, pt, targs) // try again, dropping defult arguments
else {
val deepPt = pt.deepenProto
if (deepPt ne pt) resolveOverloaded(alts, deepPt, targs)
else alts
else candidates
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/pos/i7082.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
object Overloads {

def foo[V](x: Int = 0, y: Int = 0, z: Int = 0): Nothing = ???

def foo[V](x: Int, y: Int): Nothing = ???

def foo[V](x: Int): Nothing = ???

foo(1)

}