@@ -860,7 +860,7 @@ trait Implicits:
860
860
/** Find an implicit conversion to apply to given tree `from` so that the
861
861
* result is compatible with type `to`.
862
862
*/
863
- def inferView (from : Tree , to : Type )(using Context ): SearchResult = {
863
+ def inferView (from : Tree , to : Type , maybeNameSpan : Option [ Span ] = None )(using Context ): SearchResult = {
864
864
record(" inferView" )
865
865
if ! ctx.mode.is(Mode .ImplicitsEnabled ) || from.isInstanceOf [Super ] then
866
866
NoMatchingImplicitsFailure
@@ -878,7 +878,7 @@ trait Implicits:
878
878
}
879
879
880
880
try
881
- val inferred = inferImplicit(adjust(to), from, from.span)
881
+ val inferred = inferImplicit(adjust(to), from, from.span, maybeNameSpan )
882
882
883
883
inferred match {
884
884
case SearchSuccess (_, ref, _, false ) if isOldStyleFunctionConversion(ref.underlying) =>
@@ -1059,7 +1059,7 @@ trait Implicits:
1059
1059
* it should be applied, EmptyTree otherwise.
1060
1060
* @param span The position where errors should be reported.
1061
1061
*/
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 =
1063
1063
trace(s " search implicit ${pt.show}, arg = ${argument.show}: ${argument.tpe.show}" , implicits, show = true ) {
1064
1064
record(" inferImplicit" )
1065
1065
assert(ctx.phase.allowsImplicitSearch,
@@ -1082,7 +1082,7 @@ trait Implicits:
1082
1082
(searchCtx.scope eq ctx.scope) && (searchCtx.owner eq ctx.owner.owner)
1083
1083
do ()
1084
1084
1085
- try ImplicitSearch (pt, argument, span)(using searchCtx).bestImplicit
1085
+ try ImplicitSearch (pt, argument, span, maybeNameSpan )(using searchCtx).bestImplicit
1086
1086
catch case ce : CyclicReference =>
1087
1087
ce.inImplicitSearch = true
1088
1088
throw ce
@@ -1102,9 +1102,9 @@ trait Implicits:
1102
1102
result
1103
1103
case result : SearchFailure if result.isAmbiguous =>
1104
1104
val deepPt = pt.deepenProto
1105
- if (deepPt ne pt) inferImplicit(deepPt, argument, span)
1105
+ if (deepPt ne pt) inferImplicit(deepPt, argument, span, maybeNameSpan )
1106
1106
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 {
1108
1108
case altResult : SearchSuccess =>
1109
1109
report.migrationWarning(
1110
1110
result.reason.msg
@@ -1125,7 +1125,7 @@ trait Implicits:
1125
1125
}
1126
1126
1127
1127
/** 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 ) {
1129
1129
if ctx.run.nn.isCancelled then NoMatchingImplicitsFailure
1130
1130
else
1131
1131
record(" typedImplicit" )
@@ -1164,7 +1164,9 @@ trait Implicits:
1164
1164
case selProto @ SelectionProto (selName : TermName , mbrType, _, _) =>
1165
1165
1166
1166
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)
1168
1170
1169
1171
def tryConversionForSelection (using Context ) =
1170
1172
val converted = tryConversion
@@ -1215,7 +1217,7 @@ trait Implicits:
1215
1217
}
1216
1218
1217
1219
/** 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 ):
1219
1221
assert(argument.isEmpty || argument.tpe.isValueType || argument.tpe.isInstanceOf [ExprType ],
1220
1222
em " found: $argument: ${argument.tpe}, expected: $pt" )
1221
1223
@@ -1264,7 +1266,7 @@ trait Implicits:
1264
1266
val history = ctx.searchHistory.nest(cand, pt)
1265
1267
val typingCtx =
1266
1268
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)
1268
1270
result match
1269
1271
case res : SearchSuccess =>
1270
1272
ctx.searchHistory.defineBynameImplicit(wideProto, res)
0 commit comments