Skip to content

Commit 2deb5f5

Browse files
committed
REPL: Fix root cause unwrapping
Fixing ReplCompilerTests i14701.
1 parent e2a5290 commit 2deb5f5

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package repl
33

44
import scala.language.unsafeNulls
55

6-
import java.lang.{ ClassLoader, ExceptionInInitializerError }
7-
import java.lang.reflect.InvocationTargetException
8-
96
import dotc.*, core.*
107
import Contexts.*, Denotations.*, Flags.*, NameOps.*, StdNames.*, Symbols.*
118
import printing.ReplPrinter
@@ -170,9 +167,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
170167

171168
/** Render the stack trace of the underlying exception. */
172169
def renderError(thr: Throwable, d: Denotation)(using Context): Diagnostic =
173-
val cause = thr.getCause match
174-
case e: ExceptionInInitializerError => e.getCause
175-
case e => e
170+
val cause = rootCause(thr)
176171
// detect
177172
//at repl$.rs$line$2$.<clinit>(rs$line$2:1)
178173
//at repl$.rs$line$2.res1(rs$line$2)
@@ -186,7 +181,6 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
186181
private def infoDiagnostic(msg: String, d: Denotation)(using Context): Diagnostic =
187182
new Diagnostic.Info(msg, d.symbol.sourcePos)
188183

189-
190184
object Rendering:
191185
final val REPL_WRAPPER_NAME_PREFIX = str.REPL_SESSION_LINE
192186

@@ -196,3 +190,12 @@ object Rendering:
196190
val text = printer.dclText(s)
197191
text.mkString(ctx.settings.pageWidth.value, ctx.settings.printLines.value)
198192
}
193+
194+
def rootCause(x: Throwable): Throwable = x match
195+
case _: ExceptionInInitializerError |
196+
_: java.lang.reflect.InvocationTargetException |
197+
_: java.lang.reflect.UndeclaredThrowableException |
198+
_: java.util.concurrent.ExecutionException
199+
if x.getCause != null =>
200+
rootCause(x.getCause)
201+
case _ => x

0 commit comments

Comments
 (0)