@@ -3483,28 +3483,41 @@ class Typer extends Namer
3483
3483
}
3484
3484
3485
3485
// try an extension method in scope
3486
- pt match {
3486
+ pt match
3487
3487
case selProto @ SelectionProto (selName : TermName , mbrType, _, _) =>
3488
+ val origCtx = ctx
3488
3489
def tryExtension (using Context ): Tree =
3490
+ var tried : untpd.Tree = untpd.EmptyTree
3489
3491
try
3490
3492
findRef(selName, WildcardType , ExtensionMethod , tree.srcPos) match
3491
3493
case ref : TermRef =>
3492
- extMethodApply(untpd.ref(ref).withSpan(tree.span), tree, mbrType)
3494
+ tried = untpd.ref(ref).withSpan(tree.span)
3495
+ extMethodApply(tried, tree, mbrType)
3493
3496
case _ => findRef(selProto.extensionName, WildcardType , ExtensionMethod , tree.srcPos) match
3494
3497
case ref : TermRef =>
3495
- extMethodApply(untpd.ref(ref).withSpan(tree.span), tree, mbrType)
3498
+ tried = untpd.ref(ref).withSpan(tree.span)
3499
+ extMethodApply(tried, tree, mbrType)
3496
3500
case _ => EmptyTree
3497
- catch case ex : TypeError => errorTree(tree, ex, tree.srcPos)
3501
+ catch case ex : TypeError =>
3502
+ ex match
3503
+ case ex : CyclicReference if ex.denot.is(Extension ) && ex.denot.name == selName =>
3504
+ report.warning(
3505
+ em """ An extension method for `. $selName` was tried but could not be fully constructed
3506
+ |since there was a cyclic reference involving ${ex.denot.symbol.showLocated}""" ,
3507
+ tree.srcPos)(using origCtx)
3508
+ case _ =>
3509
+ if tried.isEmpty then EmptyTree
3510
+ else errorTree(tried, ex, tree.srcPos)
3511
+
3498
3512
val nestedCtx = ctx.fresh.setNewTyperState()
3499
- val app = tryExtension(using nestedCtx)
3500
- if ( ! app .isEmpty && ! nestedCtx.reporter.hasErrors) {
3513
+ val tried = tryExtension(using nestedCtx)
3514
+ if ! tried .isEmpty && ! nestedCtx.reporter.hasErrors then
3501
3515
nestedCtx.typerState.commit()
3502
- return ExtMethodApply (app )
3503
- }
3504
- else if ! app.isEmpty then
3505
- rememberSearchFailure(tree, SearchFailure (app .withType(FailedExtension (app , pt))))
3516
+ return ExtMethodApply (tried )
3517
+ else if ! tried.isEmpty then
3518
+ rememberSearchFailure(tree,
3519
+ SearchFailure (tried .withType(FailedExtension (tried , pt))))
3506
3520
case _ =>
3507
- }
3508
3521
3509
3522
// try an implicit conversion
3510
3523
val prevConstraint = ctx.typerState.constraint
0 commit comments