diff --git a/compiler/src/dotty/tools/repl/Rendering.scala b/compiler/src/dotty/tools/repl/Rendering.scala index 17c876661e18..b246b75dd5c1 100644 --- a/compiler/src/dotty/tools/repl/Rendering.scala +++ b/compiler/src/dotty/tools/repl/Rendering.scala @@ -167,11 +167,14 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) { val cause = ite.getCause match case e: ExceptionInInitializerError => e.getCause case e => e - def isWrapperCode(ste: StackTraceElement) = - ste.getClassName == d.symbol.owner.name.show + // detect + //at repl$.rs$line$2$.(rs$line$2:1) + //at repl$.rs$line$2.res1(rs$line$2) + def isWrapperInitialization(ste: StackTraceElement) = + ste.getClassName.startsWith(nme.REPL_PACKAGE.toString + ".") // d.symbol.owner.name.show is simple name && (ste.getMethodName == nme.STATIC_CONSTRUCTOR.show || ste.getMethodName == nme.CONSTRUCTOR.show) - cause.formatStackTracePrefix(!isWrapperCode(_)) + cause.formatStackTracePrefix(!isWrapperInitialization(_)) end renderError private def infoDiagnostic(msg: String, d: Denotation)(using Context): Diagnostic = diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index bc06727f2ea4..3a050a998964 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -219,6 +219,17 @@ class ReplCompilerTests extends ReplTest { run("val (x: 1) = 2") assertEquals("scala.MatchError: 2 (of class java.lang.Integer)", storedOutput().linesIterator.next()) } + @Test def `i12920 must truncate stack trace to user code` = fromInitialState { implicit state => + run("???") + val all = lines() + assertEquals(3, all.length) + assertEquals("scala.NotImplementedError: an implementation is missing", all.head) + /* avoid asserting much about line number or elided count + scala.NotImplementedError: an implementation is missing + at scala.Predef$.$qmark$qmark$qmark(Predef.scala:344) + ... 28 elided + */ + } } object ReplCompilerTests {