Skip to content

Commit

Permalink
add -Ydebug-error option
Browse files Browse the repository at this point in the history
add a test to ensure that it works

remove an obsolete option

remove the bulk of the stacktrace in the checkfile
  • Loading branch information
tribbloid committed Feb 19, 2022
1 parent 9312709 commit 2242a7d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion project/ScalaOptionParser.scala
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
Expand Up @@ -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"
Expand Down
13 changes: 10 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/Contexts.scala
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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`,
Expand Down
5 changes: 5 additions & 0 deletions 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
25 changes: 25 additions & 0 deletions 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)
}
}

0 comments on commit 2242a7d

Please sign in to comment.