@@ -823,6 +823,9 @@ trait Implicits { self: Typer =>
823
823
SearchSuccess (generated1, ref, cand.level)(ctx.typerState)
824
824
}}
825
825
826
+ /** Try to type-check implicit reference, after checking that this is not
827
+ * a diverging search
828
+ */
826
829
def tryImplicit (cand : Candidate ): SearchResult = {
827
830
val history = ctx.searchHistory nest wildProto
828
831
if (history eq ctx.searchHistory)
@@ -831,10 +834,18 @@ trait Implicits { self: Typer =>
831
834
typedImplicit(cand)(nestedContext().setNewTyperState().setSearchHistory(history))
832
835
}
833
836
837
+ /** Compare previous success with reference and level to determine which one would be chosen, if
838
+ * an implicit starting with the reference was found.
839
+ */
834
840
def compareCandidate (prev : SearchSuccess , ref : TermRef , level : Int ): Int =
835
841
if (prev.ref eq ref) 0
836
842
else ctx.typerState.test(compare(prev.ref, ref, prev.level, level)(nestedContext()))
837
843
844
+ /** If `alt1` is also a search success, try to disambiguate as follows:
845
+ * - If alt2 is preferred over alt1, pick alt2.
846
+ * - Otherwise, if both alternatives return numeric value types, pick the one
847
+ * with the larger type.
848
+ */
838
849
def disambiguate (alt1 : SearchResult , alt2 : SearchSuccess ) = alt1 match {
839
850
case alt1 : SearchSuccess =>
840
851
def isNumeric (tp : Type ) = tp.typeSymbol.isNumericValueClass
0 commit comments