@@ -90,7 +90,9 @@ trait Implicits {
90
90
if (shouldPrint)
91
91
typingStack.printTyping(tree, " typing implicit: %s %s" .format(tree, context.undetparamsString))
92
92
val implicitSearchContext = context.makeImplicit(reportAmbiguous)
93
- val search = new ImplicitSearch (tree, pt, isView, implicitSearchContext, pos)
93
+ val dpt = if (isView) pt else dropByName(pt)
94
+ val isByName = dpt ne pt
95
+ val search = new ImplicitSearch (tree, dpt, isView, isByName, implicitSearchContext, pos)
94
96
pluginsNotifyImplicitSearch(search)
95
97
val result = search.bestImplicit
96
98
pluginsNotifyImplicitSearchResult(result)
@@ -152,7 +154,7 @@ trait Implicits {
152
154
val tvars = tpars map (TypeVar untouchable _)
153
155
val tpSubsted = tp.subst(tpars, tvars)
154
156
155
- val search = new ImplicitSearch (EmptyTree , functionType(List (tpSubsted), AnyTpe ), true , context.makeImplicit(reportAmbiguousErrors = false ))
157
+ val search = new ImplicitSearch (EmptyTree , functionType(List (tpSubsted), AnyTpe ), true , false , context.makeImplicit(reportAmbiguousErrors = false ))
156
158
157
159
search.allImplicitsPoly(tvars)
158
160
}
@@ -291,11 +293,16 @@ trait Implicits {
291
293
private def isView_= (value : Boolean ): Unit = _isView = value
292
294
293
295
private [this ] var _isView : Boolean = false
296
+
297
+ def isByName : Boolean = _isByName
298
+ private def isByName_= (value : Boolean ): Unit = _isByName = value
299
+ private [this ] var _isByName : Boolean = false
294
300
}
295
301
object OpenImplicit {
296
- def apply (info : ImplicitInfo , pt : Type , tree : Tree , isView : Boolean ): OpenImplicit = {
302
+ def apply (info : ImplicitInfo , pt : Type , tree : Tree , isView : Boolean , isByName : Boolean ): OpenImplicit = {
297
303
val result = new OpenImplicit (info, pt, tree)
298
304
result.isView = isView
305
+ result.isByName = isByName
299
306
result
300
307
}
301
308
}
@@ -382,7 +389,7 @@ trait Implicits {
382
389
* (useful when we infer synthetic stuff and pass EmptyTree in the `tree` argument)
383
390
* If it's set to NoPosition, then position-based services will use `tree.pos`
384
391
*/
385
- class ImplicitSearch (val tree : Tree , val pt : Type , val isView : Boolean , val context0 : Context , val pos0 : Position = NoPosition ) extends Typer (context0) with ImplicitsContextErrors {
392
+ class ImplicitSearch (val tree : Tree , val pt : Type , val isView : Boolean , val isByNamePt : Boolean , val context0 : Context , val pos0 : Position = NoPosition ) extends Typer (context0) with ImplicitsContextErrors {
386
393
val searchId = implicitSearchId()
387
394
private def typingLog (what : String , msg : => String ) = {
388
395
if (printingOk(tree))
@@ -532,9 +539,7 @@ trait Implicits {
532
539
val existsDominatedImplicit : Boolean =
533
540
if (tree == EmptyTree ) false
534
541
else {
535
- val ptByName = isByNameParamType(pt)
536
- val dpt = if (ptByName) dropByName(pt) else pt
537
- lazy val spt = stripped(core(dpt))
542
+ lazy val spt = stripped(core(pt))
538
543
lazy val sptSyms = allSymbols(spt)
539
544
// Are all the symbols of the stripped core of pt contained in the stripped core of tp?
540
545
def coversPt (tp : Type ): Boolean = {
@@ -547,51 +552,49 @@ trait Implicits {
547
552
ois match {
548
553
case Nil => false
549
554
case (hd@ OpenImplicit (info1, tp, tree1)) :: tl =>
550
- val byName = isByNameParamType(tp)
551
- val dtp = if (byName) dropByName(tp) else tp
552
555
(if (! info1.sym.isMacro && tree1.symbol == tree.symbol) {
553
- if (belowByName && (dtp =:= dpt )) Some (false ) // if there is a byname argument between tp and pt we can tie the knot
554
- else if (dominates(dpt, dtp ) && coversPt(dtp )) Some (true )
556
+ if (belowByName && (tp =:= pt )) Some (false ) // if there is a byname argument between tp and pt we can tie the knot
557
+ else if (dominates(pt, tp ) && coversPt(tp )) Some (true )
555
558
else None
556
559
} else None ) match {
557
560
case Some (res) => res
558
- case None => loop(tl, byName || belowByName)
561
+ case None => loop(tl, hd.isByName || belowByName)
559
562
}
560
563
}
561
564
}
562
- loop(context.openImplicits, ptByName )
565
+ loop(context.openImplicits, this .isByNamePt )
563
566
}
564
567
565
568
if (existsDominatedImplicit) {
566
569
// println("Pending implicit "+pending+" dominates "+pt+"/"+undetParams) //@MDEBUG
567
570
DivergentSearchFailure
568
571
} else {
569
- val ref = context.refByNameImplicit(dropByName(pt) )
572
+ val ref = context.refByNameImplicit(pt )
570
573
if (ref != EmptyTree )
571
574
new SearchResult (ref, EmptyTreeTypeSubstituter , Nil )
572
575
else {
573
576
val recursiveImplicit : Option [OpenImplicit ] =
574
577
if (tree == EmptyTree ) None
575
578
else context.openImplicits find {
576
- case OpenImplicit (info, tp, tree1) =>
577
- (isByNameParamType(tp) || isByNameParamType(pt)) && dropByName(tp) <:< dropByName(pt)
579
+ case oi @ OpenImplicit (info, tp, tree1) =>
580
+ (oi.isByName || isByNamePt) && oi.pt <:< pt
578
581
}
579
582
580
583
recursiveImplicit match {
581
584
case Some (rec) =>
582
- val ref = atPos(pos.focus)(context.linkByNameImplicit(dropByName( rec.pt) ))
585
+ val ref = atPos(pos.focus)(context.linkByNameImplicit(rec.pt))
583
586
new SearchResult (ref, EmptyTreeTypeSubstituter , Nil )
584
587
case None =>
585
588
try {
586
- context.openImplicits = OpenImplicit (info, pt, tree, isView) :: context.openImplicits
589
+ context.openImplicits = OpenImplicit (info, pt, tree, isView, isByNamePt ) :: context.openImplicits
587
590
// println(" "*context.openImplicits.length+"typed implicit "+info+" for "+pt) //@MDEBUG
588
591
val result = typedImplicit0(info, ptChecked, isLocalToCallsite)
589
592
if (result.isDivergent) {
590
593
// println("DivergentImplicit for pt:"+ pt +", open implicits:"+context.openImplicits) //@MDEBUG
591
594
if (context.openImplicits.tail.isEmpty && ! pt.isErroneous)
592
595
DivergingImplicitExpansionError (tree, pt, info.sym)(context)
593
596
result
594
- } else context.defineByNameImplicit(dropByName(pt) , result)
597
+ } else context.defineByNameImplicit(pt , result)
595
598
} finally {
596
599
context.openImplicits = context.openImplicits.tail
597
600
}
@@ -688,7 +691,7 @@ trait Implicits {
688
691
case NullaryMethodType (restpe) => loop(restpe, pt)
689
692
case PolyType (_, restpe) => loop(restpe, pt)
690
693
case ExistentialType (_, qtpe) => if (fast) loop(qtpe, pt) else normalize(tp) <:< pt // is !fast case needed??
691
- case _ => if (fast) isPlausiblySubType(tp, if (isView) pt else dropByName(pt)) else tp <:< dropByName(pt)
694
+ case _ => if (fast) isPlausiblySubType(tp, pt) else tp <:< pt
692
695
}
693
696
loop(tp0, pt0)
694
697
}
@@ -758,7 +761,7 @@ trait Implicits {
758
761
typingLog(" considering" , typeDebug.ptTree(itree1))
759
762
760
763
@ inline def fail (reason : => String ): SearchResult = failure(itree0, reason)
761
- def fallback = typed1(itree1, EXPRmode , dropByName( wildPt) )
764
+ def fallback = typed1(itree1, EXPRmode , wildPt)
762
765
try {
763
766
val itree2 = if (! isView) fallback else pt match {
764
767
case Function1 (arg1, arg2) =>
@@ -796,7 +799,7 @@ trait Implicits {
796
799
if (StatisticsStatics .areSomeColdStatsEnabled) statistics.incCounter(typedImplicits)
797
800
798
801
val itree3 = if (isView) treeInfo.dissectApplied(itree2).callee
799
- else adapt(itree2, EXPRmode , dropByName( wildPt) )
802
+ else adapt(itree2, EXPRmode , wildPt)
800
803
801
804
typingStack.showAdapt(itree0, itree3, pt, context)
802
805
0 commit comments