From 8d2d62374449066bd4bbc0e6a5d8b60c7575cdd6 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 13 Jan 2023 17:54:24 +0000 Subject: [PATCH] REPL: Don't crash if completions throw --- compiler/src/dotty/tools/repl/ReplDriver.scala | 3 ++- compiler/test/dotty/tools/repl/TabcompleteTests.scala | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index f076333cf449..b072d58f6bb7 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -37,6 +37,7 @@ import org.jline.reader._ import scala.annotation.tailrec import scala.collection.mutable import scala.jdk.CollectionConverters._ +import scala.util.control.NonFatal import scala.util.Using /** The state of the REPL contains necessary bindings instead of having to have @@ -241,7 +242,7 @@ class ReplDriver(settings: Array[String], unit.tpdTree = tree given Context = state.context.fresh.setCompilationUnit(unit) val srcPos = SourcePosition(file, Span(cursor)) - val (_, completions) = Completion.completions(srcPos) + val completions = try Completion.completions(srcPos)._2 catch case NonFatal(_) => Nil completions.map(_.label).distinct.map(makeCandidate) } .getOrElse(Nil) diff --git a/compiler/test/dotty/tools/repl/TabcompleteTests.scala b/compiler/test/dotty/tools/repl/TabcompleteTests.scala index 9cdb896963f1..ab735a07b092 100644 --- a/compiler/test/dotty/tools/repl/TabcompleteTests.scala +++ b/compiler/test/dotty/tools/repl/TabcompleteTests.scala @@ -233,4 +233,8 @@ class TabcompleteTests extends ReplTest { val comp = tabComplete("BigInt(1).") assertTrue(comp.distinct.nonEmpty) } + + @Test def i9334 = initially { + assertEquals(Nil, tabComplete("class Foo[T]; classOf[Foo].")) + } }