Skip to content

Commit ff14efd

Browse files
tgodzikWojciechMazur
authored andcommitted
bugfix: Fix possible SuspendException thrown when using macros
Fixes scalameta/metals#7872 [Cherry-picked 3dfa5ee]
1 parent d6cf057 commit ff14efd

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -591,12 +591,15 @@ object Completion:
591591
case _: MethodOrPoly => tpe
592592
case _ => ExprType(tpe)
593593

594+
// Try added due to https://github.com/scalameta/metals/issues/7872
594595
def tryApplyingReceiverToExtension(termRef: TermRef): Option[SingleDenotation] =
595-
ctx.typer.tryApplyingExtensionMethod(termRef, qual)
596-
.map { tree =>
597-
val tpe = asDefLikeType(tree.typeOpt.dealias)
598-
termRef.denot.asSingleDenotation.mapInfo(_ => tpe)
599-
}
596+
try
597+
ctx.typer.tryApplyingExtensionMethod(termRef, qual)
598+
.map { tree =>
599+
val tpe = asDefLikeType(tree.typeOpt.dealias)
600+
termRef.denot.asSingleDenotation.mapInfo(_ => tpe)
601+
}
602+
catch case NonFatal(_) => None
600603

601604
def extractMemberExtensionMethods(types: Seq[Type]): Seq[(TermRef, TermName)] =
602605
object DenotWithMatchingName:
@@ -694,13 +697,13 @@ object Completion:
694697
* @param qual The argument to which the implicit conversion should be applied.
695698
* @return The set of types after `qual` implicit conversion.
696699
*/
697-
private def implicitConversionTargets(qual: tpd.Tree)(using Context): Set[SearchSuccess] = {
700+
private def implicitConversionTargets(qual: tpd.Tree)(using Context): Set[SearchSuccess] = try {
698701
val typer = ctx.typer
699702
val conversions = new typer.ImplicitSearch(defn.AnyType, qual, pos.span, Set.empty).allImplicits
700703

701704
interactiv.println(i"implicit conversion targets considered: ${conversions.toList}%, %")
702705
conversions
703-
}
706+
} catch case NonFatal(_) => Set.empty
704707

705708
/** Filter for names that should appear when looking for completions. */
706709
private object completionsFilter extends NameFilter:

0 commit comments

Comments
 (0)