summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2010-08-20 14:48:12 +0000
committerAdriaan Moors <adriaan.moors@epfl.ch>2010-08-20 14:48:12 +0000
commite11cac6ecc3c8791be3a37fc3b9f6837c9d46d23 (patch)
treedfa0ddc52703125288c6d7a85c4dc7befdb1508c /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parentd4645f93728ee8cb40a17c23f92a272e27052889 (diff)
downloadscala-e11cac6ecc3c8791be3a37fc3b9f6837c9d46d23.tar.gz
scala-e11cac6ecc3c8791be3a37fc3b9f6837c9d46d23.tar.bz2
scala-e11cac6ecc3c8791be3a37fc3b9f6837c9d46d23.zip
closes 2462. better implicit error messages.
@implicitNotFound(msg="Custom error message that may refer to type parameters ${T} and ${U}") trait Constraint[T, U] whenever an implicit argument of type Constraint[A, B] cannot be found, the custom error message will be used, where the type arguments are interpolated in the obvious way note: if the msg in the annotation references non-existing type params, a warning is emitted the patch also cleans up annotation argument retrieval (moved it to AnnotationInfo from Symbol) review by odersky
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 6b8c2fe0b4..b389a4c033 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -191,6 +191,15 @@ trait Typers { self: Analyzer =>
argResultsBuff += inferImplicit(fun, paramTp, true, false, context)
}
+ def errorMessage(paramName: Name, paramTp: Type) =
+ paramTp.typeSymbol match {
+ case ImplicitNotFoundMsg(msg) => msg.format(paramName, paramTp)
+ case _ =>
+ "could not find implicit value for "+
+ (if (paramName startsWith nme.EVIDENCE_PARAM_PREFIX) "evidence parameter of type "
+ else "parameter "+paramName+": ")+paramTp
+ }
+
val argResults = argResultsBuff.toList
val args = argResults.zip(params) flatMap {
case (arg, param) =>
@@ -199,10 +208,7 @@ trait Typers { self: Analyzer =>
else List(atPos(arg.tree.pos)(new AssignOrNamedArg(Ident(param.name), (arg.tree))))
} else {
if (!param.hasFlag(DEFAULTPARAM))
- context.error(
- fun.pos, "could not find implicit value for "+
- (if (param.name startsWith nme.EVIDENCE_PARAM_PREFIX) "evidence parameter of type "
- else "parameter "+param.name+": ")+param.tpe)
+ context.error(fun.pos, errorMessage(param.name, param.tpe))
positional = false
Nil
}