diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-07-01 11:10:23 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-07-01 11:10:23 +0000 |
commit | 6cee8d5837b77e5a3ba18affb802fbb466f004ee (patch) | |
tree | 6af7a9217ff5dba47563c7e4d3f0c0e30d256ca5 /src/compiler | |
parent | 7ac2fc34f7fabf846b4d5ebecf26eb63d123ab4b (diff) | |
download | scala-6cee8d5837b77e5a3ba18affb802fbb466f004ee.tar.gz scala-6cee8d5837b77e5a3ba18affb802fbb466f004ee.tar.bz2 scala-6cee8d5837b77e5a3ba18affb802fbb466f004ee.zip |
added "diagnostic" to context.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Contexts.scala | 13 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 2 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 5b98b070ce..114525aabc 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -110,6 +110,7 @@ trait Contexts { self: Analyzer => var returnsSeen = false // for method context: were returns encountered? var reportAmbiguousErrors = false var reportGeneralErrors = false + var diagnostic: List[String] = Nil // these messages are printed when issuing an error var implicitsEnabled = false var checking = false var retyping = false @@ -208,6 +209,7 @@ trait Contexts { self: Analyzer => c.imports = imports c.reportAmbiguousErrors = this.reportAmbiguousErrors c.reportGeneralErrors = this.reportGeneralErrors + c.diagnostic = this.diagnostic c.implicitsEnabled = this.implicitsEnabled c.checking = this.checking c.retyping = this.retyping @@ -291,8 +293,12 @@ trait Contexts { self: Analyzer => c } + private def diagString = + if (diagnostic.isEmpty) "" + else diagnostic.mkString("\n","\n", "") + def error(pos: Position, err: Error) { - val msg = err.getMessage() + val msg = err.getMessage() + diagString if (reportGeneralErrors) unit.error(pos, if (checking) "**** ERROR DURING INTERNAL CHECKING ****\n" + msg else msg) else @@ -300,10 +306,11 @@ trait Contexts { self: Analyzer => } def error(pos: Position, msg: String) { + val msg1 = msg + diagString if (reportGeneralErrors) - unit.error(pos, if (checking) "**** ERROR DURING INTERNAL CHECKING ****\n" + msg else msg) + unit.error(pos, if (checking) "**** ERROR DURING INTERNAL CHECKING ****\n" + msg1 else msg1) else - throw new TypeError(pos, msg) + throw new TypeError(pos, msg1) } def warning(pos: Position, msg: String) { diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index b0226af4e3..d6bcd4f6eb 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2040,6 +2040,8 @@ trait Typers { self: Analyzer => } val (allArgs, missing) = addDefaults(args, qual, targs, previousArgss, params, fun.pos) if (allArgs.length == formals.length) { + // useful when a default doesn't match parameter type, e.g. def f[T](x:T="a"); f[Int]() + context.diagnostic = "Error occured in an application involving default arguments." :: context.diagnostic doTypedApply(tree, if (blockIsEmpty) fun else fun1, allArgs, mode, pt) } else { tryTupleApply.getOrElse { |