Skip to content

Commit 6f0f8df

Browse files
committed
Survive bad references when looking for completions
1 parent 19ea673 commit 6f0f8df

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ object Completion {
8585
* @param content The source content that we'll check the positions for the prefix
8686
* @param start The start position we'll start to look for the prefix at
8787
* @param end The end position we'll look for the prefix at
88-
* @return Either the full prefix including the ` or an empty string
88+
* @return Either the full prefix including the ` or an empty string
8989
*/
90-
private def checkBacktickPrefix(content: Array[Char], start: Int, end: Int): String =
90+
private def checkBacktickPrefix(content: Array[Char], start: Int, end: Int): String =
9191
content.lift(start) match
9292
case Some(char) if char == '`' =>
9393
content.slice(start, end).mkString
@@ -111,7 +111,7 @@ object Completion {
111111
// Foo.`se<TAB> will result in Select(Ident(Foo), <error>)
112112
case (select: untpd.Select) :: _ if select.name == nme.ERROR =>
113113
checkBacktickPrefix(select.source.content(), select.nameSpan.start, select.span.end)
114-
114+
115115
// import scala.util.chaining.`s<TAB> will result in a Ident(<error>)
116116
case (ident: untpd.Ident) :: _ if ident.name == nme.ERROR =>
117117
checkBacktickPrefix(ident.source.content(), ident.span.start, ident.span.end)
@@ -177,14 +177,14 @@ object Completion {
177177
// https://github.com/com-lihaoyi/Ammonite/blob/73a874173cd337f953a3edc9fb8cb96556638fdd/amm/util/src/main/scala/ammonite/util/Model.scala
178178
private def needsBacktick(s: String) =
179179
val chunks = s.split("_", -1)
180-
180+
181181
val validChunks = chunks.zipWithIndex.forall { case (chunk, index) =>
182182
chunk.forall(Chars.isIdentifierPart) ||
183183
(chunk.forall(Chars.isOperatorPart) &&
184184
index == chunks.length - 1 &&
185185
!(chunks.lift(index - 1).contains("") && index - 1 == 0))
186186
}
187-
187+
188188
val validStart =
189189
Chars.isIdentifierStart(s(0)) || chunks(0).forall(Chars.isOperatorPart)
190190

@@ -312,7 +312,7 @@ object Completion {
312312

313313
/** Replaces underlying type with reduced one, when it's MatchType */
314314
def reduceUnderlyingMatchType(qual: Tree)(using Context): Tree=
315-
qual.tpe.widen match
315+
qual.tpe.widen match
316316
case ctx.typer.MatchTypeInDisguise(mt) => qual.withType(mt)
317317
case _ => qual
318318

@@ -392,11 +392,13 @@ object Completion {
392392
case _ => ExprType(tpe)
393393

394394
def tryApplyingReceiverToExtension(termRef: TermRef): Option[SingleDenotation] =
395-
ctx.typer.tryApplyingExtensionMethod(termRef, qual)
396-
.map { tree =>
397-
val tpe = asDefLikeType(tree.tpe.dealias)
398-
termRef.denot.asSingleDenotation.mapInfo(_ => tpe)
399-
}
395+
try
396+
ctx.typer.tryApplyingExtensionMethod(termRef, qual)
397+
.map { tree =>
398+
val tpe = asDefLikeType(tree.tpe.dealias)
399+
termRef.denot.asSingleDenotation.mapInfo(_ => tpe)
400+
}
401+
catch case ex: TypeError => None
400402

401403
def extractMemberExtensionMethods(types: Seq[Type]): Seq[(TermRef, TermName)] =
402404
object DenotWithMatchingName:

0 commit comments

Comments
 (0)