@@ -6,16 +6,12 @@ import scala.language.unsafeNulls
66import java .lang .{ ClassLoader , ExceptionInInitializerError }
77import java .lang .reflect .InvocationTargetException
88
9- import dotc .core .Contexts ._
10- import dotc .core .Denotations .Denotation
11- import dotc .core .Flags
12- import dotc .core .Flags ._
13- import dotc .core .NameOps .*
14- import dotc .core .Symbols .{Symbol , defn }
15- import dotc .core .StdNames .{nme , str }
16- import dotc .printing .ReplPrinter
17- import dotc .reporting .Diagnostic
18- import dotc .transform .ValueClasses
9+ import dotc .* , core .*
10+ import Contexts .* , Denotations .* , Flags .* , NameOps .* , StdNames .* , Symbols .*
11+ import printing .ReplPrinter
12+ import reporting .Diagnostic
13+ import transform .ValueClasses
14+ import util .StackTraceOps .*
1915
2016import scala .util .control .NonFatal
2117
@@ -109,7 +105,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
109105 *
110106 * Calling this method evaluates the expression using reflection
111107 */
112- private def valueOf (sym : Symbol )(using Context ): Option [String ] = try
108+ private def valueOf (sym : Symbol )(using Context ): Option [String ] =
113109 val objectName = sym.owner.fullName.encode.toString.stripSuffix(" $" )
114110 val resObj : Class [? ] = Class .forName(objectName, true , classLoader())
115111 val symValue = resObj
@@ -126,9 +122,6 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
126122 else
127123 s
128124 }
129- catch
130- case e : InvocationTargetException => throw e
131- case e : ReflectiveOperationException => throw InvocationTargetException (e)
132125
133126 /** Rewrap value class to their Wrapper class
134127 *
@@ -160,15 +153,15 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
160153 infoDiagnostic(d.symbol.showUser, d)
161154
162155 /** Render value definition result */
163- def renderVal (d : Denotation )(using Context ): Either [InvocationTargetException , Option [Diagnostic ]] =
156+ def renderVal (d : Denotation )(using Context ): Either [ReflectiveOperationException , Option [Diagnostic ]] =
164157 val dcl = d.symbol.showUser
165158 def msg (s : String ) = infoDiagnostic(s, d)
166159 try
167160 Right (
168161 if d.symbol.is(Flags .Lazy ) then Some (msg(dcl))
169162 else valueOf(d.symbol).map(value => msg(s " $dcl = $value" ))
170163 )
171- catch case e : InvocationTargetException => Left (e)
164+ catch case e : ReflectiveOperationException => Left (e)
172165 end renderVal
173166
174167 /** Force module initialization in the absence of members. */
@@ -179,15 +172,11 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
179172 Nil
180173 try load()
181174 catch
182- case e : ExceptionInInitializerError => List (renderError(e, sym.denot))
183- case NonFatal (e) => List (renderError(InvocationTargetException (e) , sym.denot))
175+ case e : ExceptionInInitializerError => List (renderError(e.getCause , sym.denot))
176+ case NonFatal (e) => List (renderError(e , sym.denot))
184177
185178 /** Render the stack trace of the underlying exception. */
186- def renderError (ite : InvocationTargetException | ExceptionInInitializerError , d : Denotation )(using Context ): Diagnostic =
187- import dotty .tools .dotc .util .StackTraceOps ._
188- val cause = ite.getCause match
189- case e : ExceptionInInitializerError => e.getCause
190- case e => e
179+ def renderError (cause : Throwable , d : Denotation )(using Context ): Diagnostic =
191180 // detect
192181 // at repl$.rs$line$2$.<clinit>(rs$line$2:1)
193182 // at repl$.rs$line$2.res1(rs$line$2)
0 commit comments