summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-27 20:10:48 +0000
committerPaul Phillips <paulp@improving.org>2010-02-27 20:10:48 +0000
commit646c478b3aeb05079c915c217272bcb64dc324fc (patch)
tree49b13dbe0a74b6bd4b70e709c4ea7e7f392858cb /src/compiler/scala/tools/nsc/typechecker/Implicits.scala
parentddecf6008320f148b3e06ee76d4b81376546db98 (diff)
downloadscala-646c478b3aeb05079c915c217272bcb64dc324fc.tar.gz
scala-646c478b3aeb05079c915c217272bcb64dc324fc.tar.bz2
scala-646c478b3aeb05079c915c217272bcb64dc324fc.zip
Special cased an error message for the common s...
Special cased an error message for the common situation of calling AnyRef methods on Any or AnyVal. Review by odersky.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Implicits.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index 840ec1113d..adafcb2617 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -302,10 +302,25 @@ self: Analyzer =>
if (isView) {
val found = pt.typeArgs(0)
val req = pt.typeArgs(1)
- typeErrorMsg(found, req)+
- "\nNote that implicit conversions are not applicable because they are ambiguous:\n "+
- coreMsg+"are possible conversion functions from "+ found+" to "+req
- } else {
+
+ /** A nice spot to explain some common situations a little
+ * less confusingly.
+ */
+ def explanation = {
+ if ((found =:= AnyClass.tpe) && (AnyRefClass.tpe <:< req))
+ "Note: Any is not implicitly converted to AnyRef. You can safely\n" +
+ "pattern match x: AnyRef or cast x.asInstanceOf[AnyRef] to do so."
+ else if ((found <:< AnyValClass.tpe) && (AnyRefClass.tpe <:< req))
+ "Note: primitive types are not implicitly converted to AnyRef.\n" +
+ "You can safely force boxing by casting x.asInstanceOf[AnyRef]."
+ else
+ "Note that implicit conversions are not applicable because they are ambiguous:\n "+
+ coreMsg+"are possible conversion functions from "+ found+" to "+req
+ }
+
+ typeErrorMsg(found, req) + "\n" + explanation
+ }
+ else {
"ambiguous implicit values:\n "+coreMsg + "match expected type "+pt
})
}