@@ -3,9 +3,6 @@ package repl
33
44import scala .language .unsafeNulls
55
6- import java .lang .{ ClassLoader , ExceptionInInitializerError }
7- import java .lang .reflect .InvocationTargetException
8-
96import dotc .* , core .*
107import Contexts .* , Denotations .* , Flags .* , NameOps .* , StdNames .* , Symbols .*
118import 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-
190184object 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