Skip to content

Commit 2a45761

Browse files
committed
Merge pull request #551 from dotty-staging/fix/#547-overloaded-varargs
Fix #547: Vararg overload
2 parents 8838aef + 7645024 commit 2a45761

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,10 @@ trait Applications extends Compatibility { self: Typer =>
849849
case tp @ ExprType(tp1) => tp.derivedExprType(repeatedToSingle(tp1))
850850
case _ => if (tp.isRepeatedParam) tp.argTypesHi.head else tp
851851
}
852-
isApplicable(alt2, tp1.paramTypes map repeatedToSingle, WildcardType) ||
852+
val formals1 =
853+
if (tp1.isVarArgsMethod && tp2.isVarArgsMethod) tp1.paramTypes map repeatedToSingle
854+
else tp1.paramTypes
855+
isApplicable(alt2, formals1, WildcardType) ||
853856
tp1.paramTypes.isEmpty && tp2.isInstanceOf[MethodOrPoly]
854857
case _ =>
855858
tp2 match {
@@ -878,7 +881,7 @@ trait Applications extends Compatibility { self: Typer =>
878881
def winsOwner2 = isDerived(owner2, owner1)
879882
def winsType2 = isAsSpecific(alt2, tp2, alt1, tp1)
880883

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

883886
// Assume the following probabilities:
884887
//
@@ -1013,6 +1016,7 @@ trait Applications extends Compatibility { self: Typer =>
10131016
if (isDetermined(candidates)) candidates
10141017
else narrowMostSpecific(candidates) match {
10151018
case result @ (alt1 :: alt2 :: _) =>
1019+
// overload.println(i"ambiguous $alt1 $alt2")
10161020
val deepPt = pt.deepenProto
10171021
if (deepPt ne pt) resolveOverloaded(alts, deepPt, targs)
10181022
else result

tests/pos/varargs.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ object varargs {
1010
g(Nil: _*)
1111
g(1)
1212
g()
13+
14+
def f(x: Int): Unit = ()
15+
def f(x: Int*): Unit = ()
16+
f(1)
1317
}

0 commit comments

Comments
 (0)