@@ -975,13 +975,10 @@ trait Implicits:
975
975
if (argument.isEmpty) i " missing implicit parameter of type $pt after typer "
976
976
else i " type error: ${argument.tpe} does not conform to $pt${err.whyNoMatchStr(argument.tpe, pt)}" )
977
977
val result0 =
978
- try
979
- new ImplicitSearch (pt, argument, span).bestImplicit(contextual = true )
980
- catch {
981
- case ce : CyclicReference =>
982
- ce.inImplicitSearch = true
983
- throw ce
984
- }
978
+ try ImplicitSearch (pt, argument, span).bestImplicit
979
+ catch case ce : CyclicReference =>
980
+ ce.inImplicitSearch = true
981
+ throw ce
985
982
986
983
val result =
987
984
result0 match {
@@ -1121,7 +1118,7 @@ trait Implicits:
1121
1118
}
1122
1119
1123
1120
/** Search a list of eligible implicit references */
1124
- def searchImplicits (eligible : List [Candidate ], contextual : Boolean ): SearchResult = {
1121
+ private def searchImplicit (eligible : List [Candidate ], contextual : Boolean ): SearchResult =
1125
1122
1126
1123
/** Compare previous success with reference and level to determine which one would be chosen, if
1127
1124
* an implicit starting with the reference was found.
@@ -1292,11 +1289,33 @@ trait Implicits:
1292
1289
}
1293
1290
1294
1291
rank(sort(eligible), NoMatchingImplicitsFailure , Nil )
1295
- }
1296
- // end searchImplicits
1292
+ end searchImplicit
1293
+
1294
+ private def searchImplicit (contextual : Boolean ): SearchResult =
1295
+ val eligible =
1296
+ if contextual then ctx.implicits.eligible(wildProto)
1297
+ else implicitScope(wildProto).eligible
1298
+ searchImplicit(eligible, contextual) match
1299
+ case result : SearchSuccess =>
1300
+ result
1301
+ case failure : SearchFailure =>
1302
+ failure.reason match
1303
+ case _ : AmbiguousImplicits => failure
1304
+ case reason =>
1305
+ if contextual then
1306
+ searchImplicit(contextual = false ).recoverWith {
1307
+ failure2 => failure2.reason match
1308
+ case _ : AmbiguousImplicits => failure2
1309
+ case _ =>
1310
+ reason match
1311
+ case (_ : DivergingImplicit ) => failure
1312
+ case _ => List (failure, failure2).maxBy(_.tree.treeSize)
1313
+ }
1314
+ else failure
1315
+ end searchImplicit
1297
1316
1298
1317
/** Find a unique best implicit reference */
1299
- def bestImplicit ( contextual : Boolean ) : SearchResult =
1318
+ def bestImplicit : SearchResult =
1300
1319
// Before searching for contextual or implicit scope candidates we first check if
1301
1320
// there is an under construction or already constructed term with which we can tie
1302
1321
// the knot.
@@ -1305,35 +1324,12 @@ trait Implicits:
1305
1324
// effectively in a more inner context than any other definition provided by
1306
1325
// explicit definitions. Consequently these terms have the highest priority and no
1307
1326
// other candidates need to be considered.
1308
- recursiveRef(pt) match {
1327
+ recursiveRef match
1309
1328
case ref : TermRef =>
1310
1329
SearchSuccess (tpd.ref(ref).withSpan(span.startPos), ref, 0 )(ctx.typerState, ctx.gadt)
1311
1330
case _ =>
1312
- val eligible =
1313
- if (contextual) ctx.implicits.eligible(wildProto)
1314
- else implicitScope(wildProto).eligible
1315
- searchImplicits(eligible, contextual) match {
1316
- case result : SearchSuccess =>
1317
- result
1318
- case failure : SearchFailure =>
1319
- failure.reason match {
1320
- case _ : AmbiguousImplicits => failure
1321
- case reason =>
1322
- if (contextual)
1323
- bestImplicit(contextual = false ).recoverWith {
1324
- failure2 => failure2.reason match {
1325
- case _ : AmbiguousImplicits => failure2
1326
- case _ =>
1327
- reason match {
1328
- case (_ : DivergingImplicit ) => failure
1329
- case _ => List (failure, failure2).maxBy(_.tree.treeSize)
1330
- }
1331
- }
1332
- }
1333
- else failure
1334
- }
1335
- }
1336
- }
1331
+ searchImplicit(contextual = true )
1332
+ end bestImplicit
1337
1333
1338
1334
def implicitScope (tp : Type ): OfTypeImplicits = ctx.run.implicitScope(tp)
1339
1335
@@ -1413,7 +1409,7 @@ trait Implicits:
1413
1409
* @param pt The target type being searched for.
1414
1410
* @result The corresponding dictionary reference if any, NoType otherwise.
1415
1411
*/
1416
- def recursiveRef (pt : Type )( using Context ): Type =
1412
+ def recursiveRef (using Context ): Type =
1417
1413
val widePt = pt.widenExpr
1418
1414
1419
1415
ctx.searchHistory.refBynameImplicit(widePt).orElse {
0 commit comments