@@ -11,7 +11,7 @@ import dotc.core.Denotations.Denotation
1111import dotc .core .Flags
1212import dotc .core .Flags ._
1313import dotc .core .Symbols .{Symbol , defn }
14- import dotc .core .StdNames .str
14+ import dotc .core .StdNames .{ nme , str }
1515import dotc .core .NameOps ._
1616import dotc .printing .ReplPrinter
1717import dotc .reporting .{MessageRendering , Message , Diagnostic }
@@ -120,20 +120,22 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
120120 if (d.symbol.is(Flags .Lazy )) Some (infoDiagnostic(dcl, d))
121121 else valueOf(d.symbol).map(value => infoDiagnostic(s " $dcl = $value" , d))
122122 }
123- catch { case ex : InvocationTargetException => Some (infoDiagnostic(renderError(ex), d)) }
123+ catch { case ex : InvocationTargetException => Some (infoDiagnostic(renderError(ex, d ), d)) }
124124 }
125125
126- /** Render the stack trace of the underlying exception */
127- private def renderError (ex : InvocationTargetException ): String = {
128- val cause = ex.getCause match {
126+ /** Render the stack trace of the underlying exception. */
127+ private def renderError (ite : InvocationTargetException , d : Denotation )(using Context ): String =
128+ import dotty .tools .dotc .util .StackTraceOps ._
129+ val cause = ite.getCause match {
129130 case ex : ExceptionInInitializerError => ex.getCause
130131 case ex => ex
131132 }
132- val sw = new StringWriter ()
133- val pw = new PrintWriter (sw)
134- cause.printStackTrace(pw)
135- sw.toString
136- }
133+ def isWrapperCode (ste : StackTraceElement ) =
134+ ste.getClassName == d.symbol.owner.name.show
135+ && (ste.getMethodName == nme.STATIC_CONSTRUCTOR .show || ste.getMethodName == nme.CONSTRUCTOR .show)
136+
137+ cause.formatStackTracePrefix(! isWrapperCode(_))
138+ end renderError
137139
138140 private def infoDiagnostic (msg : String , d : Denotation )(using Context ): Diagnostic =
139141 new Diagnostic .Info (msg, d.symbol.sourcePos)
0 commit comments