@@ -579,10 +579,10 @@ trait Implicits {
579579 private def typedImplicit1 (info : ImplicitInfo , isLocal : Boolean ): SearchResult = {
580580 if (Statistics .canEnable) Statistics .incCounter(matchingImplicits)
581581
582- val itree = atPos(pos.focus) {
583- // workaround for deficient context provided by ModelFactoryImplicitSupport#makeImplicitConstraints
584- val isScalaDoc = context.tree == EmptyTree
582+ // workaround for deficient context provided by ModelFactoryImplicitSupport#makeImplicitConstraints
583+ val isScalaDoc = context.tree == EmptyTree
585584
585+ val itree = atPos(pos.focus) {
586586 if (isLocal && ! isScalaDoc) {
587587 // SI-4270 SI-5376 Always use an unattributed Ident for implicits in the local scope,
588588 // rather than an attributed Select, to detect shadowing.
@@ -605,7 +605,23 @@ trait Implicits {
605605 atPos(itree.pos)(Apply (itree, List (Ident (" <argument>" ) setType approximate(arg1)))),
606606 EXPRmode ,
607607 approximate(arg2)
608- )
608+ ) match {
609+ // try to infer implicit parameters immediately in order to:
610+ // 1) guide type inference for implicit views
611+ // 2) discard ineligible views right away instead of risking spurious ambiguous implicits
612+ //
613+ // this is an improvement of the state of the art that brings consistency to implicit resolution rules
614+ // (and also helps fundep materialization to be applicable to implicit views)
615+ //
616+ // there's one caveat though. we need to turn this behavior off for scaladoc
617+ // because scaladoc usually doesn't know the entire story
618+ // and is just interested in views that are potentially applicable
619+ // for instance, if we have `class C[T]` and `implicit def conv[T: Numeric](c: C[T]) = ???`
620+ // then Scaladoc will give us something of type `C[T]`, and it would like to know
621+ // that `conv` is potentially available under such and such conditions
622+ case tree if isImplicitMethodType(tree.tpe) && ! isScalaDoc => applyImplicitArgs(tree)
623+ case tree => tree
624+ }
609625 case _ => fallback
610626 }
611627 context.firstError match { // using match rather than foreach to avoid non local return.
@@ -617,7 +633,7 @@ trait Implicits {
617633
618634 if (Statistics .canEnable) Statistics .incCounter(typedImplicits)
619635
620- val itree2 = if (isView) (itree1 : @ unchecked) match { case Apply (fun, _) => fun }
636+ val itree2 = if (isView) treeInfo.dissectApplied (itree1).callee
621637 else adapt(itree1, EXPRmode , wildPt)
622638
623639 typingStack.showAdapt(itree, itree2, pt, context)
0 commit comments