@@ -1355,7 +1355,7 @@ trait Implicits:
1355
1355
* @param pt The target type for the above candidate.
1356
1356
* @result True if this candidate/pt are divergent, false otherwise.
1357
1357
*/
1358
- def checkDivergence (cand : Candidate )( using Context ) : Boolean =
1358
+ def checkDivergence (cand : Candidate ): Boolean =
1359
1359
// For full details of the algorithm see the SIP:
1360
1360
// https://docs.scala-lang.org/sips/byname-implicits.html
1361
1361
util.Stats .record(" checkDivergence" )
@@ -1374,7 +1374,6 @@ trait Implicits:
1374
1374
history match
1375
1375
case OpenSearch (cand1, tp, outer) =>
1376
1376
if cand1.ref eq cand.ref then
1377
- util.Stats .record(" checkDivergence for sure" )
1378
1377
val wideTp = tp.widenExpr
1379
1378
lazy val wildTp = wildApprox(wideTp)
1380
1379
lazy val tpSize = wideTp.typeSize
@@ -1409,30 +1408,28 @@ trait Implicits:
1409
1408
* @param pt The target type being searched for.
1410
1409
* @result The corresponding dictionary reference if any, NoType otherwise.
1411
1410
*/
1412
- def recursiveRef (using Context ): Type =
1413
- val widePt = pt.widenExpr
1414
-
1415
- ctx.searchHistory.refBynameImplicit(widePt).orElse {
1416
- val bynamePt = pt.isByName
1417
- if (! ctx.searchHistory.byname && ! bynamePt) NoType // No recursion unless at least one open implicit is by name ...
1418
- else {
1419
- // We are able to tie a recursive knot if there is compatible term already under
1420
- // construction which is separated from this context by at least one by name
1421
- // argument as we ascend the chain of open implicits to the outermost search
1422
- // context.
1423
- @ tailrec
1424
- def loop (history : SearchHistory , belowByname : Boolean ): Type =
1425
- history match
1426
- case OpenSearch (cand, tp, outer) =>
1427
- if (belowByname || tp.isByName) && tp.widenExpr <:< widePt then tp
1428
- else loop(outer, belowByname || tp.isByName)
1429
- case _ => NoType
1430
-
1431
- loop(ctx.searchHistory, bynamePt) match
1432
- case NoType => NoType
1433
- case tp => ctx.searchHistory.linkBynameImplicit(tp.widenExpr)
1434
- }
1435
- }
1411
+ def recursiveRef : Type =
1412
+ val found = ctx.searchHistory.refBynameImplicit(wideProto)
1413
+ if found.exists then
1414
+ found
1415
+ else if ! ctx.searchHistory.byname && ! pt.isByName then
1416
+ NoType // No recursion unless at least one open implicit is by name ...
1417
+ else
1418
+ // We are able to tie a recursive knot if there is compatible term already under
1419
+ // construction which is separated from this context by at least one by name
1420
+ // argument as we ascend the chain of open implicits to the outermost search
1421
+ // context.
1422
+ @ tailrec
1423
+ def loop (history : SearchHistory , belowByname : Boolean ): Type =
1424
+ history match
1425
+ case OpenSearch (cand, tp, outer) =>
1426
+ if (belowByname || tp.isByName) && tp.widenExpr <:< wideProto then tp
1427
+ else loop(outer, belowByname || tp.isByName)
1428
+ case _ => NoType
1429
+
1430
+ loop(ctx.searchHistory, pt.isByName) match
1431
+ case NoType => NoType
1432
+ case tp => ctx.searchHistory.linkBynameImplicit(tp.widenExpr)
1436
1433
end recursiveRef
1437
1434
end ImplicitSearch
1438
1435
end Implicits
@@ -1529,7 +1526,9 @@ final class SearchRoot extends SearchHistory:
1529
1526
* @result The corresponding TermRef, or NoType if none.
1530
1527
*/
1531
1528
override def refBynameImplicit (tpe : Type )(using Context ): Type =
1532
- implicitDictionary.get(tpe).map(_._1).getOrElse(NoType )
1529
+ implicitDictionary.get(tpe) match
1530
+ case Some ((tp, _)) => tp
1531
+ case None => NoType
1533
1532
1534
1533
/**
1535
1534
* Define a pending dictionary entry if any.
0 commit comments