Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 96aff06

Browse files
bugfix: Fix possible SuspendException thrown when using macros (#24174)
Fixes scalameta/metals#7872
2 parents f1cbbe9 + 078be56 commit 96aff06

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
@@ -35,6 +35,8 @@ import dotty.tools.dotc.core.Constants
3535
import dotty.tools.dotc.core.TypeOps
3636
import dotty.tools.dotc.core.StdNames
3737

38+
import java.util.logging.Logger
39+
3840
/**
3941
* One of the results of a completion query.
4042
*
@@ -48,6 +50,8 @@ case class Completion(label: String, description: String, symbols: List[Symbol])
4850

4951
object Completion:
5052

53+
private val logger = Logger.getLogger(this.getClass.getName)
54+
5155
def scopeContext(pos: SourcePosition)(using Context): CompletionResult =
5256
val tpdPath = Interactive.pathTo(ctx.compilationUnit.tpdTree, pos.span)
5357
val completionContext = Interactive.contextOfPath(tpdPath).withPhase(Phases.typerPhase)
@@ -601,12 +605,19 @@ object Completion:
601605
case _: MethodOrPoly => tpe
602606
case _ => ExprType(tpe)
603607

608+
// Try added due to https://github.com/scalameta/metals/issues/7872
604609
def tryApplyingReceiverToExtension(termRef: TermRef): Option[SingleDenotation] =
605-
ctx.typer.tryApplyingExtensionMethod(termRef, qual)
606-
.map { tree =>
607-
val tpe = asDefLikeType(tree.typeOpt.dealias)
608-
termRef.denot.asSingleDenotation.mapInfo(_ => tpe)
609-
}
610+
try
611+
ctx.typer.tryApplyingExtensionMethod(termRef, qual)
612+
.map { tree =>
613+
val tpe = asDefLikeType(tree.typeOpt.dealias)
614+
termRef.denot.asSingleDenotation.mapInfo(_ => tpe)
615+
}
616+
catch case NonFatal(ex) =>
617+
logger.warning(
618+
s"Exception when trying to apply extension method:\n${ex.getMessage()}\n${ex.getStackTrace().mkString("\n")}"
619+
)
620+
None
610621

611622
def extractMemberExtensionMethods(types: Seq[Type]): Seq[(TermRef, TermName)] =
612623
object DenotWithMatchingName:
@@ -704,13 +715,17 @@ object Completion:
704715
* @param qual The argument to which the implicit conversion should be applied.
705716
* @return The set of types after `qual` implicit conversion.
706717
*/
707-
private def implicitConversionTargets(qual: tpd.Tree)(using Context): Set[SearchSuccess] = {
718+
private def implicitConversionTargets(qual: tpd.Tree)(using Context): Set[SearchSuccess] = try{
708719
val typer = ctx.typer
709720
val conversions = new typer.ImplicitSearch(defn.AnyType, qual, pos.span, Set.empty).allImplicits
710721

711722
interactiv.println(i"implicit conversion targets considered: ${conversions.toList}%, %")
712723
conversions
713-
}
724+
} catch case NonFatal(ex) =>
725+
logger.warning(
726+
s"Exception when searching for implicit conversions:\n${ex.getMessage()}\n${ex.getStackTrace().mkString("\n")}"
727+
)
728+
Set.empty
714729

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /