Skip to content

Tweak REPL stack truncation for package name #12921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/repl/Rendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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$.<clinit>(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 =
Expand Down
11 changes: 11 additions & 0 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down