@@ -6,16 +6,12 @@ import scala.language.unsafeNulls
6
6
import java .lang .{ ClassLoader , ExceptionInInitializerError }
7
7
import java .lang .reflect .InvocationTargetException
8
8
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 .*
19
15
20
16
import scala .util .control .NonFatal
21
17
@@ -109,7 +105,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
109
105
*
110
106
* Calling this method evaluates the expression using reflection
111
107
*/
112
- private def valueOf (sym : Symbol )(using Context ): Option [String ] = try
108
+ private def valueOf (sym : Symbol )(using Context ): Option [String ] =
113
109
val objectName = sym.owner.fullName.encode.toString.stripSuffix(" $" )
114
110
val resObj : Class [? ] = Class .forName(objectName, true , classLoader())
115
111
val symValue = resObj
@@ -126,9 +122,6 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
126
122
else
127
123
s
128
124
}
129
- catch
130
- case e : InvocationTargetException => throw e
131
- case e : ReflectiveOperationException => throw InvocationTargetException (e)
132
125
133
126
/** Rewrap value class to their Wrapper class
134
127
*
@@ -160,15 +153,15 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
160
153
infoDiagnostic(d.symbol.showUser, d)
161
154
162
155
/** 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 ]] =
164
157
val dcl = d.symbol.showUser
165
158
def msg (s : String ) = infoDiagnostic(s, d)
166
159
try
167
160
Right (
168
161
if d.symbol.is(Flags .Lazy ) then Some (msg(dcl))
169
162
else valueOf(d.symbol).map(value => msg(s " $dcl = $value" ))
170
163
)
171
- catch case e : InvocationTargetException => Left (e)
164
+ catch case e : ReflectiveOperationException => Left (e)
172
165
end renderVal
173
166
174
167
/** Force module initialization in the absence of members. */
@@ -179,15 +172,11 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
179
172
Nil
180
173
try load()
181
174
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))
184
177
185
178
/** 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 =
191
180
// detect
192
181
// at repl$.rs$line$2$.<clinit>(rs$line$2:1)
193
182
// at repl$.rs$line$2.res1(rs$line$2)
0 commit comments