Skip to content

Commit 0b0f626

Browse files
committed
Fix #14701: avoid REPL crash when input is of the form val _ = ???
The REPL should not crash when the right hand side of `val _ =` throws a non-fatal error that is a subclass of java.lang.Error.
1 parent 4f1ad71 commit 0b0f626

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,15 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
142142

143143
/** Force module initialization in the absence of members. */
144144
def forceModule(sym: Symbol)(using Context): Seq[Diagnostic] =
145+
import scala.util.control.NonFatal
145146
def load() =
146147
val objectName = sym.fullName.encode.toString
147148
Class.forName(objectName, true, classLoader())
148149
Nil
149-
try load() catch case e: ExceptionInInitializerError => List(renderError(e, sym.denot))
150+
try load()
151+
catch
152+
case e: ExceptionInInitializerError => List(renderError(e, sym.denot))
153+
case NonFatal(e) => List(renderError(InvocationTargetException(e), sym.denot))
150154

151155
/** Render the stack trace of the underlying exception. */
152156
def renderError(ite: InvocationTargetException | ExceptionInInitializerError, d: Denotation)(using Context): Diagnostic =

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

+13
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,19 @@ class ReplCompilerTests extends ReplTest:
334334
assertEquals("scala.MatchError: hi (of class java.lang.String)", all.head)
335335
}
336336

337+
@Test def i14701 = initially {
338+
val state = run("val _ = ???")
339+
val all = lines()
340+
assertEquals(3, all.length)
341+
assertEquals("scala.NotImplementedError: an implementation is missing", all.head)
342+
state
343+
} andThen {
344+
run("val _ = assert(false)")
345+
val all = lines()
346+
assertEquals(3, all.length)
347+
assertEquals("java.lang.AssertionError: assertion failed", all.head)
348+
}
349+
337350
@Test def i14491 =
338351
initially {
339352
run("import language.experimental.fewerBraces")

0 commit comments

Comments
 (0)