From 906c94e53d715313735d2449779ae8f8bd7cb92a Mon Sep 17 00:00:00 2001 From: peng Date: Fri, 3 Dec 2021 02:58:10 -0500 Subject: [PATCH] add -Ydebug-error option add a test to ensure that it works remove an obsolete option remove the bulk of the stacktrace in the checkfile --- project/ScalaOptionParser.scala | 2 +- .../tools/nsc/settings/ScalaSettings.scala | 3 ++- .../tools/nsc/typechecker/Contexts.scala | 13 +++++++--- test/files/run/debug-error.check | 5 ++++ test/files/run/debug-error.scala | 25 +++++++++++++++++++ 5 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 test/files/run/debug-error.check create mode 100644 test/files/run/debug-error.scala diff --git a/project/ScalaOptionParser.scala b/project/ScalaOptionParser.scala index 64d9db857982..ae13d7d9c4b7 100644 --- a/project/ScalaOptionParser.scala +++ b/project/ScalaOptionParser.scala @@ -86,7 +86,7 @@ object ScalaOptionParser { "-Xno-forwarders", "-Xno-patmat-analysis", "-Xnon-strict-patmat-analysis", "-Xprint-pos", "-Xprint-types", "-Xprompt", "-Xresident", "-Xshow-phases", "-Xverify", "-Y", "-Ybreak-cycles", "-Ydebug", "-Ycompact-trees", "-YdisableFlatCpCaching", "-Ydoc-debug", "-Yide-debug", - "-Yissue-debug", "-Ylog-classpath", "-Ymacro-debug-lite", "-Ymacro-debug-verbose", "-Ymacro-no-expand", + "-Ydebug-error", "-Ylog-classpath", "-Ymacro-debug-lite", "-Ymacro-debug-verbose", "-Ymacro-no-expand", "-Yno-completion", "-Yno-generic-signatures", "-Yno-imports", "-Yno-predef", "-Ymacro-annotations", "-Ypatmat-debug", "-Yno-adapted-args", "-Ypos-debug", "-Ypresentation-debug", "-Ypresentation-strict", "-Ypresentation-verbose", "-Yquasiquote-debug", "-Yrangepos", "-Yreify-copypaste", "-Yreify-debug", "-Yrepl-class-based", diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index 1b25f95f46c6..d16d3592a080 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -455,9 +455,10 @@ trait ScalaSettings extends StandardScalaSettings with Warnings { _: MutableSett val browse = PhasesSetting("-Vbrowse", "Browse the abstract syntax tree after") withAbbreviation "-Ybrowse" val debug = BooleanSetting("-Vdebug", "Increase the quantity of debugging output.") withAbbreviation "-Ydebug" withPostSetHook (s => if (s.value) StatisticsStatics.enableDebugAndDeoptimize()) val YdebugTasty = BooleanSetting("-Vdebug-tasty", "Increase the quantity of debugging output when unpickling tasty.") withAbbreviation "-Ydebug-tasty" + val YdebugError = BooleanSetting("-Ydebug-error", "Print the stack trace when any error is caught.") val Ydocdebug = BooleanSetting("-Vdoc", "Trace scaladoc activity.") withAbbreviation "-Ydoc-debug" val Yidedebug = BooleanSetting("-Vide", "Generate, validate and output trees using the interactive compiler.") withAbbreviation "-Yide-debug" - val Yissuedebug = BooleanSetting("-Vissue", "Print stack traces when a context issues an error.") withAbbreviation "-Yissue-debug" +// val Yissuedebug = BooleanSetting("-Vissue", "Print stack traces when a context issues an error.") withAbbreviation "-Yissue-debug" val log = PhasesSetting("-Vlog", "Log operations during") withAbbreviation "-Ylog" val Ylogcp = BooleanSetting("-Vclasspath", "Output information about what classpath is being applied.") withAbbreviation "-Ylog-classpath" val YmacrodebugLite = BooleanSetting("-Vmacro-lite", "Trace macro activities with less output.") withAbbreviation "-Ymacro-debug-lite" diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 5c7e3128b8ed..7f8f92a31050 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -808,7 +808,7 @@ trait Contexts { self: Analyzer => /** Issue/buffer/throw the given implicit ambiguity error according to the current mode for error reporting. */ private[typechecker] def issueAmbiguousError(err: AbsAmbiguousTypeError) = reporter.issueAmbiguousError(err)(this) /** Issue/throw the given error message according to the current mode for error reporting. */ - def error(pos: Position, msg: String) = reporter.error(fixPosition(pos), msg) + def error(pos: Position, msg: String) = reporter.errorAndDump(fixPosition(pos), msg) /** Issue/throw the given error message according to the current mode for error reporting. */ def warning(pos: Position, msg: String, category: WarningCategory) = reporter.warning(fixPosition(pos), msg, category, owner) def warning(pos: Position, msg: String, category: WarningCategory, site: Symbol) = reporter.warning(fixPosition(pos), msg, category, site) @@ -1643,7 +1643,7 @@ trait Contexts { self: Analyzer => type Error = AbsTypeError type Warning = (Position, String, WarningCategory, Symbol) - def issue(err: AbsTypeError)(implicit context: Context): Unit = error(context.fixPosition(err.errPos), addDiagString(err.errMsg)) + def issue(err: AbsTypeError)(implicit context: Context): Unit = errorAndDump(context.fixPosition(err.errPos), addDiagString(err.errMsg)) def echo(msg: String): Unit = echo(NoPosition, msg) @@ -1655,6 +1655,13 @@ trait Contexts { self: Analyzer => def error(pos: Position, msg: String): Unit + final def errorAndDump(pos: Position, msg: String): Unit = { + error(pos, msg) + if (settings.YdebugError.value) { + Thread.dumpStack() + } + } + protected def handleSuppressedAmbiguous(err: AbsAmbiguousTypeError): Unit = () def makeImmediate: ContextReporter = this @@ -1686,7 +1693,7 @@ trait Contexts { self: Analyzer => if (target.isBuffering) { target ++= errors } else { - errors.foreach(e => target.error(e.errPos, e.errMsg)) + errors.foreach(e => target.errorAndDump(e.errPos, e.errMsg)) } // TODO: is clearAllErrors necessary? (no tests failed when dropping it) // NOTE: even though `this ne target`, it may still be that `target.errorBuffer eq _errorBuffer`, diff --git a/test/files/run/debug-error.check b/test/files/run/debug-error.check new file mode 100644 index 000000000000..a201aa6756b1 --- /dev/null +++ b/test/files/run/debug-error.check @@ -0,0 +1,5 @@ +newSource1.scala:3: error: object dummy is not a member of package org + val a: org.dummy.Dummy = ??? + ^ +java.lang.Exception: Stack trace +java.lang.Exception: Stack trace diff --git a/test/files/run/debug-error.scala b/test/files/run/debug-error.scala new file mode 100644 index 000000000000..7139aaad021d --- /dev/null +++ b/test/files/run/debug-error.scala @@ -0,0 +1,25 @@ +// filter: (\s*)at(.*) + +import scala.tools.partest._ + +object Test extends DirectTest { + override def extraSettings: String = "-usejavacp -Ydebug-error" + + def code: String = "" + + def noSuchType: String = """ +object Example +{ + val a: org.dummy.Dummy = ??? +} + """ + + def show(): Unit = { + val global = newCompiler() + + def run(code: String): Unit = + compileString(global)(code.trim) + + run(noSuchType) + } +}