@@ -11,7 +11,7 @@ import dotc.core.Denotations.Denotation
11
11
import dotc .core .Flags
12
12
import dotc .core .Flags ._
13
13
import dotc .core .Symbols .{Symbol , defn }
14
- import dotc .core .StdNames .str
14
+ import dotc .core .StdNames .{ nme , str }
15
15
import dotc .core .NameOps ._
16
16
import dotc .printing .ReplPrinter
17
17
import dotc .reporting .{MessageRendering , Message , Diagnostic }
@@ -115,32 +115,33 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
115
115
/** Render value definition result */
116
116
def renderVal (d : Denotation )(using Context ): Option [Diagnostic ] =
117
117
val dcl = d.symbol.showUser
118
-
118
+ def msg ( s : String ) = infoDiagnostic(s, d)
119
119
try
120
- if (d.symbol.is(Flags .Lazy )) Some (infoDiagnostic (dcl, d ))
121
- else valueOf(d.symbol).map(value => infoDiagnostic (s " $dcl = $value" , d ))
122
- catch case ex : InvocationTargetException => Some (infoDiagnostic (renderError(ex) , d))
120
+ if (d.symbol.is(Flags .Lazy )) Some (msg (dcl))
121
+ else valueOf(d.symbol).map(value => msg (s " $dcl = $value" ))
122
+ catch case e : InvocationTargetException => Some (msg (renderError(e , d) ))
123
123
end renderVal
124
124
125
125
/** Force module initialization in the absence of members. */
126
126
def forceModule (sym : Symbol )(using Context ): Seq [Diagnostic ] =
127
127
def load () =
128
128
val objectName = sym.fullName.encode.toString
129
- val resObj : Class [ ? ] = Class .forName(objectName, true , classLoader())
129
+ Class .forName(objectName, true , classLoader())
130
130
Nil
131
- try load() catch case e : ExceptionInInitializerError => List (infoDiagnostic(renderError(e), sym.denot))
131
+ try load() catch case e : ExceptionInInitializerError => List (infoDiagnostic(renderError(e, sym.denot ), sym.denot))
132
132
133
133
/** Render the stack trace of the underlying exception. */
134
- private def renderError (ex : InvocationTargetException | ExceptionInInitializerError ): String = {
135
- val cause = ex.getCause match {
136
- case ex : ExceptionInInitializerError => ex.getCause
137
- case ex => ex
138
- }
139
- val sw = new StringWriter ()
140
- val pw = new PrintWriter (sw)
141
- cause.printStackTrace(pw)
142
- sw.toString
143
- }
134
+ private def renderError (ite : InvocationTargetException | ExceptionInInitializerError , d : Denotation )(using Context ): String =
135
+ import dotty .tools .dotc .util .StackTraceOps ._
136
+ val cause = ite.getCause match
137
+ case e : ExceptionInInitializerError => e.getCause
138
+ case e => e
139
+ def isWrapperCode (ste : StackTraceElement ) =
140
+ ste.getClassName == d.symbol.owner.name.show
141
+ && (ste.getMethodName == nme.STATIC_CONSTRUCTOR .show || ste.getMethodName == nme.CONSTRUCTOR .show)
142
+
143
+ cause.formatStackTracePrefix(! isWrapperCode(_))
144
+ end renderError
144
145
145
146
private def infoDiagnostic (msg : String , d : Denotation )(using Context ): Diagnostic =
146
147
new Diagnostic .Info (msg, d.symbol.sourcePos)
0 commit comments