Skip to content

Commit 4ad5a69

Browse files
committed
Take defult parameters into account for overloading resolution.
The current Scala spec only considers methods without default parameters for overloading resolution (unless only a single one remains anyway after filtering by shape). This is needlessly restrictive. But dropping this restriction (as dotty does) can lead to ambiguity errors, which is why run/t8197 did not compile anymore. We fix the problem by a last try rule: If after asSpecific tests there are still several alternatives, and only one of them is without default arguments, pick that one. I tried an alternative rule which would make the distinction on default params earlier but that one fails for the overloaded tree copier functions in Trees.scala (the method with default parameters is also the one which is more specific).
1 parent 7bbc222 commit 4ad5a69

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ trait Applications extends Compatibility { self: Typer =>
262262
val receiver: Tree = methPart(normalizedFun) match {
263263
case Select(receiver, _) => receiver
264264
case mr => mr.tpe.normalizedPrefix match {
265-
case mr: TermRef =>
266-
ref(mr)
267-
case mr: TypeRef if this.isInstanceOf[TestApplication[_]] =>
268-
// In this case it is safe to skolemize now; we will produce a stable prefix for the actual call.
269-
ref(mr.narrow)
270-
case _ =>
271-
EmptyTree
265+
case mr: TermRef => ref(mr)
266+
case mr =>
267+
if (this.isInstanceOf[TestApplication[_]])
268+
// In this case it is safe to skolemize now; we will produce a stable prefix for the actual call.
269+
ref(mr.narrow)
270+
else
271+
EmptyTree
272272
}
273273
}
274274
val getterPrefix =
@@ -1106,10 +1106,13 @@ trait Applications extends Compatibility { self: Typer =>
11061106
// the arguments (which are constants) to be adapted to Byte. If we had picked
11071107
// `candidates` instead, no solution would have been found.
11081108
case alts =>
1109-
// overload.println(i"ambiguous $alts%, %")
1110-
val deepPt = pt.deepenProto
1111-
if (deepPt ne pt) resolveOverloaded(alts, deepPt, targs)
1112-
else alts
1109+
val noDefaults = alts.filter(!_.symbol.hasDefaultParams)
1110+
if (noDefaults.length == 1) noDefaults // return unique alternative without default parameters if it exists
1111+
else {
1112+
val deepPt = pt.deepenProto
1113+
if (deepPt ne pt) resolveOverloaded(alts, deepPt, targs)
1114+
else alts
1115+
}
11131116
}
11141117
}
11151118

0 commit comments

Comments
 (0)