8000 add -Vdebug-type-error option, with abbreviation -Ydebug-type-error · scala/scala@cb8b541 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit cb8b541

Browse files
author
peng
committed
add -Vdebug-type-error option, with abbreviation -Ydebug-type-error
add a test to ensure that it works remove an obsolete option
1 parent 9312709 commit cb8b541

File tree

5 files changed

+47
-9
lines changed

5 files changed

+47
-9
lines changed

project/ScalaOptionParser.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ object ScalaOptionParser {
8484
// TODO retrieve these data programmatically, ala https://github.com/scala/scala-tool-support/blob/master/bash-completion/src/main/scala/BashCompletion.scala
8585
private def booleanSettingNames = List("-X", "-Xasync", "-Xcheckinit", "-Xdev", "-Xdisable-assertions", "-Xexperimental", "-Xfatal-warnings", "-Xlog-free-terms", "-Xlog-free-types", "-Xlog-implicit-conversions", "-Xlog-reflective-calls",
8686
"-Xno-forwarders", "-Xno-patmat-analysis", "-Xnon-strict-patmat-analysis", "-Xprint-pos", "-Xprint-types", "-Xprompt", "-Xresident", "-Xshow-phases", "-Xverify", "-Y",
87-
"-Ybreak-cycles", "-Ydebug", "-Ycompact-trees", "-YdisableFlatCpCaching", "-Ydoc-debug",
87+
"-Ybreak-cycles", "-Ydebug", "-Ydebug-type-error", "-Ycompact-trees", "-YdisableFlatCpCaching", "-Ydoc-debug",
8888
"-Yide-debug",
89-
"-Yissue-debug", "-Ylog-classpath", "-Ymacro-debug-lite", "-Ymacro-debug-verbose", "-Ymacro-no-expand",
89+
"-Ylog-classpath", "-Ymacro-debug-lite", "-Ymacro-debug-verbose", "-Ymacro-no-expand",
9090
"-Yno-completion", "-Yno-generic-signatures", "-Yno-imports", "-Yno-predef", "-Ymacro-annotations",
9191
"-Ypatmat-debug", "-Yno-adapted-args", "-Ypos-debug", "-Ypresentation-debug",
9292
"-Ypresentation-strict", "-Ypresentation-verbose", "-Yquasiquote-debug", "-Yrangepos", "-Yreify-copypaste", "-Yreify-debug", "-Yrepl-class-based",
9393
"-Yrepl-sync", "-Yshow-member-pos", "-Yshow-symkinds", "-Yshow-symowners", "-Yshow-syms", "-Yshow-trees", "-Yshow-trees-compact", "-Yshow-trees-stringified", "-Ytyper-debug",
9494
"-Ywarn-dead-code", "-Ywarn-numeric-widen", "-Ywarn-value-discard", "-Ywarn-extra-implicit", "-Ywarn-self-implicit",
9595
"-V",
96-
"-Vclasspath", "-Vdebug", "-Vdebug-tasty", "-Vdoc", "-Vfree-terms", "-Vfree-types",
96+
"-Vclasspath", "-Vdebug", "-Vdebug-tasty", "-Vdebug-type-error", "-Vdoc", "-Vfree-terms", "-Vfree-types",
9797
"-Vhot-statistics", "-Vide", "-Vimplicit-conversions", "-Vimplicits", "-Vissue",
9898
"-Vmacro", "-Vmacro-lite", "-Vpatmat", "-Vphases", "-Vpos", "-Vprint-pos",
9999
"-Vprint-types", "-Vquasiquote", "-Vreflective-calls", "-Vreify",

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,11 @@ trait ScalaSettings extends StandardScalaSettings with Warnings { _: MutableSett
454454
val Vhelp = BooleanSetting("-V", "Print a synopsis of verbose options.")
455455
val browse = PhasesSetting("-Vbrowse", "Browse the abstract syntax tree after") withAbbreviation "-Ybrowse"
456456
val debug = BooleanSetting("-Vdebug", "Increase the quantity of debugging output.") withAbbreviation "-Ydebug" withPostSetHook (s => if (s.value) StatisticsStatics.enableDebugAndDeoptimize())
457-
val YdebugTasty = BooleanSetting("-Vdebug-tasty", "Increase the quantity of debugging output when unpickling tasty.") withAbbreviation "-Ydebug-tasty"
458-
val Ydocdebug = BooleanSetting("-Vdoc", "Trace scaladoc activity.") withAbbreviation "-Ydoc-debug"
457+
val YdebugTasty = BooleanSetting("-Vdebug-tasty", "Increase the quantity of debugging output when unpickling tasty.") withAbbreviation "-Ydebug-tasty"
458+
val VdebugTypeError = BooleanSetting("-Vdebug-type-error", "Print the stack trace when any error is caught.") withAbbreviation "-Ydebug-type-error"
459+
val Ydocdebug = BooleanSetting("-Vdoc", "Trace scaladoc activity.") withAbbreviation "-Ydoc-debug"
459460
val Yidedebug = BooleanSetting("-Vide", "Generate, vali 8000 date and output trees using the interactive compiler.") withAbbreviation "-Yide-debug"
460-
val Yissuedebug = BooleanSetting("-Vissue", "Print stack traces when a context issues an error.") withAbbreviation "-Yissue-debug"
461+
// val Yissuedebug = BooleanSetting("-Vissue", "Print stack traces when a context issues an error.") withAbbreviation "-Yissue-debug"
461462
val log = PhasesSetting("-Vlog", "Log operations during") withAbbreviation "-Ylog"
462463
val Ylogcp = BooleanSetting("-Vclasspath", "Output information about what classpath is being applied.") withAbbreviation "-Ylog-classpath"
463464
val YmacrodebugLite = BooleanSetting("-Vmacro-lite", "Trace macro activities with less output.") withAbbreviation "-Ymacro-debug-lite"

src/compiler/scala/tools/nsc/typechecker/Contexts.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ trait Contexts { self: Analyzer =>
808808
/** Issue/buffer/throw the given implicit ambiguity error according to the current mode for error reporting. */
809809
private[typechecker] def issueAmbiguousError(err: AbsAmbiguousTypeError) = reporter.issueAmbiguousError(err)(this)
810810
/** Issue/throw the given error message according to the current mode for error reporting. */
811-
def error(pos: Position, msg: String) = reporter.error(fixPosition(pos), msg)
811+
def error(pos: Position, msg: String) = reporter.errorAndDumpIfDebug(fixPosition(pos), msg)
812812
/** Issue/throw the given error message according to the current mode for error reporting. */
813813
def warning(pos: Position, msg: String, category: WarningCategory) = reporter.warning(fixPosition(pos), msg, category, owner)
814814
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 =>
16431643
type Error = AbsTypeError
16441644
type Warning = (Position, String, WarningCategory, Symbol)
16451645

1646-
def issue(err: AbsTypeError)(implicit context: Context): Unit = error(context.fixPosition(err.errPos), addDiagString(err.errMsg))
1646+
def issue(err: AbsTypeError)(implicit context: Context): Unit = errorAndDumpIfDebug(context.fixPosition(err.errPos), addDiagString(err.errMsg))
16471647

16481648
def echo(msg: String): Unit = echo(NoPosition, msg)
16491649

@@ -1655,6 +1655,13 @@ trait Contexts { self: Analyzer =>
16551655

16561656
def error(pos: Position, msg: String): Unit
16571657

1658+
final def errorAndDumpIfDebug(pos: Position, msg: String): Unit = {
1659+
error(pos, msg)
1660+
if (settings.VdebugTypeError.value) {
1661+
Thread.dumpStack()
1662+
}
1663+
}
1664+
16581665
protected def handleSuppressedAmbiguous(err: AbsAmbiguousTypeError): Unit = ()
16591666

16601667
def makeImmediate: ContextReporter = this
@@ -1686,7 +1693,7 @@ trait Contexts { self: Analyzer =>
16861693
if (target.isBuffering) {
16871694
target ++= errors
16881695
} else {
1689-
errors.foreach(e => target.error(e.errPos, e.errMsg))
1696+
errors.foreach(e => target.errorAndDumpIfDebug(e.errPos, e.errMsg))
16901697
}
16911698
// TODO: is clearAllErrors necessary? (no tests failed when dropping it)
16921699
// NOTE: even though `this ne target`, it may still be that `target.errorBuffer eq _errorBuffer`,

test/files/run/debug-type-error.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
newSource1.scala:3: error: object dummy is not a member of package org
2+
val a: org.dummy.Dummy = ???
3+
^
4+
java.lang.Exception: Stack trace
5+
java.lang.Exception: Stack trace

test/files/run/debug-type-error.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// filter: (\s*)at(.*)
2+
3+
import scala.tools.partest._
4+
5+
object Test extends DirectTest {
6+
override def extraSettings: String = "-usejavacp -Vdebug-type-error"
7+
8+
def code: String = ""
9+
10+
def noSuchType: String = """
11+
object Example
12+
{
13+
val a: org.dummy.Dummy = ???
14+
}
15+
"""
16+
17+
def show(): Unit = {
18+
val global = newCompiler()
19+
20+
def run(code: String): Unit =
21+
compileString(global)(code.trim)
22+
23+
run(noSuchType)
24+
}
25+
}

0 commit comments

Comments
 (0)
0