Skip to content

Commit 46d0b05

Browse files
authored
Merge pull request #12921 from som-snytt/issue/12920
2 parents a58a48a + f061d08 commit 46d0b05

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

compiler/src/dotty/tools/repl/Rendering.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,14 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
168168
val cause = ite.getCause match
169169
case e: ExceptionInInitializerError => e.getCause
170170
case e => e
171-
def isWrapperCode(ste: StackTraceElement) =
172-
ste.getClassName == d.symbol.owner.name.show
171+
// detect
172+
//at repl$.rs$line$2$.<clinit>(rs$line$2:1)
173+
//at repl$.rs$line$2.res1(rs$line$2)
174+
def isWrapperInitialization(ste: StackTraceElement) =
175+
ste.getClassName.startsWith(nme.REPL_PACKAGE.toString + ".") // d.symbol.owner.name.show is simple name
173176
&& (ste.getMethodName == nme.STATIC_CONSTRUCTOR.show || ste.getMethodName == nme.CONSTRUCTOR.show)
174177

175-
cause.formatStackTracePrefix(!isWrapperCode(_))
178+
cause.formatStackTracePrefix(!isWrapperInitialization(_))
176179
end renderError
177180

178181
private def infoDiagnostic(msg: String, d: Denotation)(using Context): Diagnostic =

compiler/test/dotty/tools/repl/ReplCompilerTests.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,17 @@ class ReplCompilerTests extends ReplTest {
219219
run("val (x: 1) = 2")
220220
assertEquals("scala.MatchError: 2 (of class java.lang.Integer)", storedOutput().linesIterator.next())
221221
}
222+
@Test def `i12920 must truncate stack trace to user code` = fromInitialState { implicit state =>
223+
run("???")
224+
val all = lines()
225+
assertEquals(3, all.length)
226+
assertEquals("scala.NotImplementedError: an implementation is missing", all.head)
227+
/* avoid asserting much about line number or elided count
228+
scala.NotImplementedError: an implementation is missing
229+
at scala.Predef$.$qmark$qmark$qmark(Predef.scala:344)
230+
... 28 elided
231+
*/
232+
}
222233
}
223234

224235
object ReplCompilerTests {

0 commit comments

Comments
 (0)