Skip to content

Commit 07af300

Browse files
authored
REPL: Don't crash if completions throw (#16687)
2 parents 722acb9 + 8d2d623 commit 07af300

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import org.jline.reader._
3737
import scala.annotation.tailrec
3838
import scala.collection.mutable
3939
import scala.jdk.CollectionConverters._
40+
import scala.util.control.NonFatal
4041
import scala.util.Using
4142

4243
/** The state of the REPL contains necessary bindings instead of having to have
@@ -241,7 +242,7 @@ class ReplDriver(settings: Array[String],
241242
unit.tpdTree = tree
242243
given Context = state.context.fresh.setCompilationUnit(unit)
243244
val srcPos = SourcePosition(file, Span(cursor))
244-
val (_, completions) = Completion.completions(srcPos)
245+
val completions = try Completion.completions(srcPos)._2 catch case NonFatal(_) => Nil
245246
completions.map(_.label).distinct.map(makeCandidate)
246247
}
247248
.getOrElse(Nil)

compiler/test/dotty/tools/repl/TabcompleteTests.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,8 @@ class TabcompleteTests extends ReplTest {
233233
val comp = tabComplete("BigInt(1).")
234234
assertTrue(comp.distinct.nonEmpty)
235235
}
236+
237+
@Test def i9334 = initially {
238+
assertEquals(Nil, tabComplete("class Foo[T]; classOf[Foo]."))
239+
}
236240
}

0 commit comments

Comments
 (0)