@@ -915,7 +915,9 @@ trait Applications extends Compatibility { self: Typer =>
915
915
}}
916
916
917
917
def narrowMostSpecific (alts : List [TermRef ])(implicit ctx : Context ): List [TermRef ] = track(" narrowMostSpecific" ) {
918
- (alts : @ unchecked) match {
918
+ alts match {
919
+ case Nil => alts
920
+ case _ :: Nil => alts
919
921
case alt :: alts1 =>
920
922
def winner (bestSoFar : TermRef , alts : List [TermRef ]): TermRef = alts match {
921
923
case alt :: alts1 =>
@@ -993,9 +995,7 @@ trait Applications extends Compatibility { self: Typer =>
993
995
* probability of pruning the search. result type comparisons are neither cheap nor
994
996
* do they prune much, on average.
995
997
*/
996
- def adaptByResult (alts : List [TermRef ], chosen : TermRef ) =
997
- if (ctx.isAfterTyper) chosen
998
- else {
998
+ def adaptByResult (alts : List [TermRef ], chosen : TermRef ) = {
999
999
def nestedCtx = ctx.fresh.setExploreTyperState
1000
1000
pt match {
1001
1001
case pt : FunProto if ! resultConforms(chosen, pt.resultType)(nestedCtx) =>
@@ -1074,14 +1074,19 @@ trait Applications extends Compatibility { self: Typer =>
1074
1074
case pt =>
1075
1075
alts filter (normalizedCompatible(_, pt))
1076
1076
}
1077
- if (isDetermined(candidates)) candidates
1078
- else narrowMostSpecific(candidates) match {
1077
+ narrowMostSpecific(candidates) match {
1079
1078
case Nil => Nil
1080
- case alt :: Nil => adaptByResult(candidates, alt) :: Nil
1079
+ case alt :: Nil =>
1080
+ adaptByResult(alts, alt) :: Nil
1081
+ // why `alts` and not `candidates`? pos/array-overload.scala gives a test case.
1082
+ // Here, only the Int-apply is a candidate, but it is not compatible with the result
1083
+ // type. Picking the Byte-apply as the only result-compatible solution then forces
1084
+ // the arguments (which are constants) to be adapted to Byte. If we had picked
1085
+ // `candidates` instead, no solution would have been found.
1081
1086
case alts =>
1082
1087
// overload.println(i"ambiguous $alts%, %")
1083
1088
val deepPt = pt.deepenProto
1084
- if (deepPt ne pt) resolveOverloaded(candidates , deepPt, targs)
1089
+ if (deepPt ne pt) resolveOverloaded(alts , deepPt, targs)
1085
1090
else alts
1086
1091
}
1087
1092
}
0 commit comments