@@ -860,7 +860,7 @@ trait Implicits:
860860 /** Find an implicit conversion to apply to given tree `from` so that the
861861 * result is compatible with type `to`.
862862 */
863- def inferView (from : Tree , to : Type )(using Context ): SearchResult = {
863+ def inferView (from : Tree , to : Type , maybeNameSpan : Option [ Span ] = None )(using Context ): SearchResult = {
864864 record(" inferView" )
865865 if ! ctx.mode.is(Mode .ImplicitsEnabled ) || from.isInstanceOf [Super ] then
866866 NoMatchingImplicitsFailure
@@ -878,7 +878,7 @@ trait Implicits:
878878 }
879879
880880 try
881- val inferred = inferImplicit(adjust(to), from, from.span)
881+ val inferred = inferImplicit(adjust(to), from, from.span, maybeNameSpan )
882882
883883 inferred match {
884884 case SearchSuccess (_, ref, _, false ) if isOldStyleFunctionConversion(ref.underlying) =>
@@ -1059,7 +1059,7 @@ trait Implicits:
10591059 * it should be applied, EmptyTree otherwise.
10601060 * @param span The position where errors should be reported.
10611061 */
1062- def inferImplicit (pt : Type , argument : Tree , span : Span )(using Context ): SearchResult =
1062+ def inferImplicit (pt : Type , argument : Tree , span : Span , maybeNameSpan : Option [ Span ] = None )(using Context ): SearchResult =
10631063 trace(s " search implicit ${pt.show}, arg = ${argument.show}: ${argument.tpe.show}" , implicits, show = true ) {
10641064 record(" inferImplicit" )
10651065 assert(ctx.phase.allowsImplicitSearch,
@@ -1082,7 +1082,7 @@ trait Implicits:
10821082 (searchCtx.scope eq ctx.scope) && (searchCtx.owner eq ctx.owner.owner)
10831083 do ()
10841084
1085- try ImplicitSearch (pt, argument, span)(using searchCtx).bestImplicit
1085+ try ImplicitSearch (pt, argument, span, maybeNameSpan )(using searchCtx).bestImplicit
10861086 catch case ce : CyclicReference =>
10871087 ce.inImplicitSearch = true
10881088 throw ce
@@ -1102,9 +1102,9 @@ trait Implicits:
11021102 result
11031103 case result : SearchFailure if result.isAmbiguous =>
11041104 val deepPt = pt.deepenProto
1105- if (deepPt ne pt) inferImplicit(deepPt, argument, span)
1105+ if (deepPt ne pt) inferImplicit(deepPt, argument, span, maybeNameSpan )
11061106 else if (migrateTo3 && ! ctx.mode.is(Mode .OldOverloadingResolution ))
1107- withMode(Mode .OldOverloadingResolution )(inferImplicit(pt, argument, span)) match {
1107+ withMode(Mode .OldOverloadingResolution )(inferImplicit(pt, argument, span, maybeNameSpan )) match {
11081108 case altResult : SearchSuccess =>
11091109 report.migrationWarning(
11101110 result.reason.msg
@@ -1125,7 +1125,7 @@ trait Implicits:
11251125 }
11261126
11271127 /** Try to typecheck an implicit reference */
1128- def typedImplicit (cand : Candidate , pt : Type , argument : Tree , span : Span )(using Context ): SearchResult = trace(i " typed implicit ${cand.ref}, pt = $pt, implicitsEnabled == ${ctx.mode is ImplicitsEnabled }" , implicits, show = true ) {
1128+ def typedImplicit (cand : Candidate , pt : Type , argument : Tree , span : Span , maybeNameSpan : Option [ Span ] = None )(using Context ): SearchResult = trace(i " typed implicit ${cand.ref}, pt = $pt, implicitsEnabled == ${ctx.mode is ImplicitsEnabled }" , implicits, show = true ) {
11291129 if ctx.run.nn.isCancelled then NoMatchingImplicitsFailure
11301130 else
11311131 record(" typedImplicit" )
@@ -1164,7 +1164,9 @@ trait Implicits:
11641164 case selProto @ SelectionProto (selName : TermName , mbrType, _, _) =>
11651165
11661166 def tryExtension (using Context ) =
1167- extMethodApply(untpd.Select (untpdGenerated, selName), argument, mbrType)
1167+ val select =
1168+ maybeNameSpan.foldLeft(untpd.Select (untpdGenerated, selName))(_.withSpan(_))
1169+ extMethodApply(select, argument, mbrType)
11681170
11691171 def tryConversionForSelection (using Context ) =
11701172 val converted = tryConversion
@@ -1215,7 +1217,7 @@ trait Implicits:
12151217 }
12161218
12171219 /** An implicit search; parameters as in `inferImplicit` */
1218- class ImplicitSearch (protected val pt : Type , protected val argument : Tree , span : Span )(using Context ):
1220+ class ImplicitSearch (protected val pt : Type , protected val argument : Tree , span : Span , maybeNameSpan : Option [ Span ] )(using Context ):
12191221 assert(argument.isEmpty || argument.tpe.isValueType || argument.tpe.isInstanceOf [ExprType ],
12201222 em " found: $argument: ${argument.tpe}, expected: $pt" )
12211223
@@ -1264,7 +1266,7 @@ trait Implicits:
12641266 val history = ctx.searchHistory.nest(cand, pt)
12651267 val typingCtx =
12661268 nestedContext().setNewTyperState().setFreshGADTBounds.setSearchHistory(history)
1267- val result = typedImplicit(cand, pt, argument, span)(using typingCtx)
1269+ val result = typedImplicit(cand, pt, argument, span, maybeNameSpan )(using typingCtx)
12681270 result match
12691271 case res : SearchSuccess =>
12701272 ctx.searchHistory.defineBynameImplicit(wideProto, res)
0 commit comments