Skip to content

Commit 1dbb437

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 fe6b4d9 commit 1dbb437

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 =
@@ -1105,10 +1105,13 @@ trait Applications extends Compatibility { self: Typer =>
11051105
// the arguments (which are constants) to be adapted to Byte. If we had picked
11061106
// `candidates` instead, no solution would have been found.
11071107
case alts =>
1108-
// overload.println(i"ambiguous $alts%, %")
1109-
val deepPt = pt.deepenProto
1110-
if (deepPt ne pt) resolveOverloaded(alts, deepPt, targs)
1111-
else alts
1108+
val noDefaults = alts.filter(!_.symbol.hasDefaultParams)
1109+
if (noDefaults.length == 1) noDefaults // return unique alternative without default parameters if it exists
1110+
else {
1111+
val deepPt = pt.deepenProto
1112+
if (deepPt ne pt) resolveOverloaded(alts, deepPt, targs)
1113+
else alts
1114+
}
11121115
}
11131116
}
11141117

0 commit comments

Comments
 (0)