diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-07-08 08:27:27 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-07-17 15:44:58 +0200 |
commit | 5895e10adb3ec3e711cd48a9d0f0f9095c7f8ab9 (patch) | |
tree | 823a665022ea7a6bcc90a9ccd91fe796544fec27 | |
parent | 67651e220a6a4d1d1ee1004766d5b1e33fd46531 (diff) | |
download | scala-5895e10adb3ec3e711cd48a9d0f0f9095c7f8ab9.tar.gz scala-5895e10adb3ec3e711cd48a9d0f0f9095c7f8ab9.tar.bz2 scala-5895e10adb3ec3e711cd48a9d0f0f9095c7f8ab9.zip |
Concretize diagnostics: one boolean suffices for now.
Once we get the next diagnostic, lets encapsulate them in an
object, with a boolean flag for each one when it needs to trigger,
and a nice message that should be presented to our delighted user.
A list of Strings that is searched by contents is a bit fragile,
and can't be very fast either.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Contexts.scala | 18 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 3 |
2 files changed, 10 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index aa2394897c..7cb2ad7ac5 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -265,8 +265,9 @@ trait Contexts { self: Analyzer => def defaultModeForTyped: Mode = if (inTypeConstructorAllowed) Mode.NOmode else Mode.EXPRmode - /** These messages are printed when issuing an error */ - var diagnostic: List[String] = Nil + /** To enrich error messages involving default arguments. + When extending the notion, group diagnostics in an object. */ + var diagUsedDefaults: Boolean = false /** Saved type bounds for type parameters which are narrowed in a GADT. */ var savedTypeBounds: List[(Symbol, Type)] = List() @@ -452,7 +453,7 @@ trait Contexts { self: Analyzer => // Fields that are directly propagated c.variance = variance - c.diagnostic = diagnostic + c.diagUsedDefaults = diagUsedDefaults c.openImplicits = openImplicits c.contextMode = contextMode // note: ConstructorSuffix, a bit within `mode`, is conditionally overwritten below. c._reportBuffer = reportBuffer @@ -532,16 +533,15 @@ trait Contexts { self: Analyzer => // // Error and warning issuance // - private def addDiagString(msg: String) = { - val ds = - if (diagnostic.isEmpty) "" - else diagnostic.mkString("\n","\n", "") - if (msg endsWith ds) msg else msg + ds + val diagUsedDefaultsMsg = "Error occurred in an application involving default arguments." + if (diagUsedDefaults && !(msg endsWith diagUsedDefaultsMsg)) msg + "\n" + diagUsedDefaultsMsg + else msg } private def unitError(pos: Position, msg: String): Unit = - if (checking) onTreeCheckerError(pos, msg) else reporter.error(pos, msg) + if (checking) onTreeCheckerError(pos, msg) + else reporter.error(pos, msg) @inline private def issueCommon(err: AbsTypeError, reportError: Boolean) { // TODO: are errors allowed to have pos == NoPosition?? diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index d35319bb8c..e0af229d3a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3357,8 +3357,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper duplErrTree } else if (lencmp2 == 0) { // useful when a default doesn't match parameter type, e.g. def f[T](x:T="a"); f[Int]() - val note = "Error occurred in an application involving default arguments." - if (!(context.diagnostic contains note)) context.diagnostic = note :: context.diagnostic + context.diagUsedDefaults = true doTypedApply(tree, if (blockIsEmpty) fun else fun1, allArgs, mode, pt) } else { rollbackNamesDefaultsOwnerChanges() |