Skip to content

Fix #547: Vararg overload #551

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
May 9, 2015
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 src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,10 @@ trait Applications extends Compatibility { self: Typer =>
case tp @ ExprType(tp1) => tp.derivedExprType(repeatedToSingle(tp1))
case _ => if (tp.isRepeatedParam) tp.argTypesHi.head else tp
}
isApplicable(alt2, tp1.paramTypes map repeatedToSingle, WildcardType) ||
val formals1 =
if (tp1.isVarArgsMethod && tp2.isVarArgsMethod) tp1.paramTypes map repeatedToSingle
else tp1.paramTypes
isApplicable(alt2, formals1, WildcardType) ||
tp1.paramTypes.isEmpty && tp2.isInstanceOf[MethodOrPoly]
case _ =>
tp2 match {
Expand Down Expand Up @@ -878,7 +881,7 @@ trait Applications extends Compatibility { self: Typer =>
def winsOwner2 = isDerived(owner2, owner1)
def winsType2 = isAsSpecific(alt2, tp2, alt1, tp1)

implicits.println(i"isAsGood($alt1, $alt2)? $tp1 $tp2 $winsOwner1 $winsType1 $winsOwner2 $winsType2")
overload.println(i"isAsGood($alt1, $alt2)? $tp1 $tp2 $winsOwner1 $winsType1 $winsOwner2 $winsType2")

// Assume the following probabilities:
//
Expand Down Expand Up @@ -1013,6 +1016,7 @@ trait Applications extends Compatibility { self: Typer =>
if (isDetermined(candidates)) candidates
else narrowMostSpecific(candidates) match {
case result @ (alt1 :: alt2 :: _) =>
// overload.println(i"ambiguous $alt1 $alt2")
val deepPt = pt.deepenProto
if (deepPt ne pt) resolveOverloaded(alts, deepPt, targs)
else result
Expand Down
4 changes: 4 additions & 0 deletions tests/pos/varargs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ object varargs {
g(Nil: _*)
g(1)
g()

def f(x: Int): Unit = ()
def f(x: Int*): Unit = ()
f(1)
}