Skip to content

Commit 7a060ba

Browse files
committed
Less implicit searches in overload resolution
If a directly applicable alternative exists, there is no need to try every alternative (which would require searching for implicit conversions for every argument that doesn't directly match). This should not affect semantics since applicable overloads that require some implicit conversions are dismissed in `narrowMostSpecific`
1 parent 044d29d commit 7a060ba

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,11 +1146,17 @@ trait Applications extends Compatibility { self: Typer =>
11461146
alts
11471147
}
11481148

1149-
def narrowByTrees(alts: List[TermRef], args: List[Tree], resultType: Type): List[TermRef] =
1150-
alts filter ( alt =>
1151-
if (!ctx.isAfterTyper) isApplicable(alt, targs, args, resultType)
1152-
else isDirectlyApplicable(alt, targs, args, resultType)
1149+
def narrowByTrees(alts: List[TermRef], args: List[Tree], resultType: Type): List[TermRef] = {
1150+
val alts2 = alts.filter(alt =>
1151+
isDirectlyApplicable(alt, targs, args, resultType)
11531152
)
1153+
if (alts2.isEmpty && !ctx.isAfterTyper)
1154+
alts.filter(alt =>
1155+
isApplicable(alt, targs, args, resultType)
1156+
)
1157+
else
1158+
alts2
1159+
}
11541160

11551161
val alts1 = narrowBySize(alts)
11561162
//ctx.log(i"narrowed by size: ${alts1.map(_.symbol.showDcl)}%, %")

0 commit comments

Comments
 (0)