summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2009-07-01 11:10:23 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2009-07-01 11:10:23 +0000
commit6cee8d5837b77e5a3ba18affb802fbb466f004ee (patch)
tree6af7a9217ff5dba47563c7e4d3f0c0e30d256ca5
parent7ac2fc34f7fabf846b4d5ebecf26eb63d123ab4b (diff)
downloadscala-6cee8d5837b77e5a3ba18affb802fbb466f004ee.tar.gz
scala-6cee8d5837b77e5a3ba18affb802fbb466f004ee.tar.bz2
scala-6cee8d5837b77e5a3ba18affb802fbb466f004ee.zip
added "diagnostic" to context.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala13
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala2
-rw-r--r--test/files/neg/names-defaults-neg.check3
3 files changed, 15 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 {
diff --git a/test/files/neg/names-defaults-neg.check b/test/files/neg/names-defaults-neg.check
index f4ab2e5f99..a6200419ce 100644
--- a/test/files/neg/names-defaults-neg.check
+++ b/test/files/neg/names-defaults-neg.check
@@ -90,11 +90,13 @@ names-defaults-neg.scala:70: error: wrong number of arguments for <none>: (x: In
^
names-defaults-neg.scala:77: error: inferred kinds of the type arguments (List[Int]) do not conform to the expected kinds of the type parameters (type T).
List[Int]'s type parameters do not match type T's expected parameters: class List has one type parameter, but type T has one
+Error occured in an application involving default arguments.
test4()
^
error: type mismatch;
found : List[Int]
required: List[List[scala.List[List[X forSome { type X }]]]]
+Error occured in an application involving default arguments.
names-defaults-neg.scala:80: error: type mismatch;
found : List[Int]
required: scala.List[scala.List[?]]
@@ -103,6 +105,7 @@ names-defaults-neg.scala:80: error: type mismatch;
names-defaults-neg.scala:83: error: type mismatch;
found : Int
required: String
+Error occured in an application involving default arguments.
new A2[String]()
^
names-defaults-neg.scala:95: error: multiple overloaded alternatives of method foo define default arguments