Skip to content

Commit fe27659

Browse files
committed
Fix tryExtensionOrConversion
1 parent 8de1265 commit fe27659

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,19 +2924,24 @@ class Typer extends Namer
29242924
(using Context): Tree =
29252925

29262926
def selectionProto = SelectionProto(tree.name, mbrProto, compat, privateOK)
2927-
// try an extension method in scope
2928-
try
2929-
val nestedCtx = ctx.fresh.setNewTyperState()
2927+
2928+
def tryExtension(using Context): Tree =
29302929
findRef(tree.name, WildcardType, ExtensionMethod, EmptyFlags, qual.srcPos) match
29312930
case ref: TermRef =>
2932-
val app = extMethodApply(untpd.ref(ref).withSpan(tree.span), qual, pt)
2933-
if !nestedCtx.reporter.hasErrors then
2934-
nestedCtx.typerState.commit()
2935-
return app
2936-
for err <- nestedCtx.reporter.allErrors.take(1) do
2937-
rememberSearchFailure(qual,
2938-
SearchFailure(app.withType(FailedExtension(app, selectionProto, err.msg))))
2931+
extMethodApply(untpd.ref(ref).withSpan(tree.span), qual, pt)
29392932
case _ =>
2933+
EmptyTree
2934+
2935+
// try an extension method in scope
2936+
try
2937+
val nestedCtx = ctx.fresh.setNewTyperState()
2938+
val app = tryExtension(using nestedCtx)
2939+
if !app.isEmpty && !nestedCtx.reporter.hasErrors then
2940+
nestedCtx.typerState.commit()
2941+
return app
2942+
for err <- nestedCtx.reporter.allErrors.take(1) do
2943+
rememberSearchFailure(qual,
2944+
SearchFailure(app.withType(FailedExtension(app, selectionProto, err.msg))))
29402945
catch case ex: TypeError =>
29412946
rememberSearchFailure(qual,
29422947
SearchFailure(qual.withType(NestedFailure(ex.toMessage, selectionProto))))

0 commit comments

Comments
 (0)