Skip to content

Commit 2db454b

Browse files
authored
Merge pull request #629 from scala/backport-lts-3.3-24174
Backport "bugfix: Fix possible SuspendException thrown when using macros" to 3.3 LTS
2 parents 458bb3b + 913408e commit 2db454b

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import dotty.tools.dotc.core.Types
3333
import dotty.tools.dotc.core.Symbols
3434
import dotty.tools.dotc.core.Constants
3535

36+
import java.util.logging.Logger
37+
3638
/**
3739
* One of the results of a completion query.
3840
*
@@ -46,6 +48,8 @@ case class Completion(label: String, description: String, symbols: List[Symbol])
4648

4749
object Completion:
4850

51+
private val logger = Logger.getLogger(this.getClass.getName)
52+
4953
def scopeContext(pos: SourcePosition)(using Context): CompletionResult =
5054
val tpdPath = Interactive.pathTo(ctx.compilationUnit.tpdTree, pos.span)
5155
val completionContext = Interactive.contextOfPath(tpdPath).withPhase(Phases.typerPhase)
@@ -563,12 +567,19 @@ object Completion:
563567
case _: MethodOrPoly => tpe
564568
case _ => ExprType(tpe)
565569

570+
// Try added due to https://github.com/scalameta/metals/issues/7872
566571
def tryApplyingReceiverToExtension(termRef: TermRef): Option[SingleDenotation] =
567-
ctx.typer.tryApplyingExtensionMethod(termRef, qual)
568-
.map { tree =>
569-
val tpe = asDefLikeType(tree.typeOpt.dealias)
570-
termRef.denot.asSingleDenotation.mapInfo(_ => tpe)
571-
}
572+
try
573+
ctx.typer.tryApplyingExtensionMethod(termRef, qual)
574+
.map { tree =>
575+
val tpe = asDefLikeType(tree.typeOpt.dealias)
576+
termRef.denot.asSingleDenotation.mapInfo(_ => tpe)
577+
}
578+
catch case NonFatal(ex) =>
579+
logger.warning(
580+
s"Exception when trying to apply extension method:\n ${ex.getMessage()}\n${ex.getStackTrace().mkString("\n")}"
581+
)
582+
None
572583

573584
def extractMemberExtensionMethods(types: Seq[Type]): Seq[(TermRef, TermName)] =
574585
object DenotWithMatchingName:
@@ -666,13 +677,17 @@ object Completion:
666677
* @param qual The argument to which the implicit conversion should be applied.
667678
* @return The set of types after `qual` implicit conversion.
668679
*/
669-
private def implicitConversionTargets(qual: tpd.Tree)(using Context): Set[SearchSuccess] = {
680+
private def implicitConversionTargets(qual: tpd.Tree)(using Context): Set[SearchSuccess] = try {
670681
val typer = ctx.typer
671682
val conversions = new typer.ImplicitSearch(defn.AnyType, qual, pos.span).allImplicits
672683

673684
interactiv.println(i"implicit conversion targets considered: ${conversions.toList}%, %")
674685
conversions
675-
}
686+
} catch case NonFatal(ex) =>
687+
logger.warning(
688+
s"Exception when searching for implicit conversions:\n ${ex.getMessage()}\n${ex.getStackTrace().mkString("\n")}"
689+
)
690+
Set.empty
676691

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

0 commit comments

Comments
 (0)