summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-05-02 15:40:27 -0700
committerPaul Phillips <paulp@improving.org>2013-05-02 23:33:28 -0700
commite86832d7e845014dd272b71e2c12f0eedd55e85a (patch)
treeeea6811444cb6756634b6f9f673ce41da5132590
parent98972c95ab1e7c0ea2af9c9a958c0de60eb26b3d (diff)
downloadscala-e86832d7e845014dd272b71e2c12f0eedd55e85a.tar.gz
scala-e86832d7e845014dd272b71e2c12f0eedd55e85a.tar.bz2
scala-e86832d7e845014dd272b71e2c12f0eedd55e85a.zip
SI-7441 Don't ramble on about inapplicable implicits.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala21
-rw-r--r--test/files/neg/t7441.check6
-rw-r--r--test/files/neg/t7441.scala7
3 files changed, 28 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index 01ae0a7a94..04e0b9d653 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -149,7 +149,7 @@ trait Implicits {
class SearchResult(val tree: Tree, val subst: TreeTypeSubstituter) {
override def toString = "SearchResult(%s, %s)".format(tree,
if (subst.isEmpty) "" else subst)
-
+
def isFailure = false
def isAmbiguousFailure = false
final def isSuccess = !isFailure
@@ -158,7 +158,7 @@ trait Implicits {
lazy val SearchFailure = new SearchResult(EmptyTree, EmptyTreeTypeSubstituter) {
override def isFailure = true
}
-
+
lazy val AmbiguousSearchFailure = new SearchResult(EmptyTree, EmptyTreeTypeSubstituter) {
override def isFailure = true
override def isAmbiguousFailure = true
@@ -892,11 +892,20 @@ trait Implicits {
*/
if (divergence)
throw DivergentImplicit
-
- if (invalidImplicits.nonEmpty)
+ else invalidImplicits take 1 foreach { sym =>
+ def isSensibleAddendum = pt match {
+ case Function1(_, out) => out <:< sym.tpe.finalResultType
+ case tp => tp <:< sym.tpe.finalResultType
+ case _ => false
+ }
+ // Don't pitch in with this theory unless it looks plausible that the
+ // implicit would have helped
setAddendum(pos, () =>
- "\n Note: implicit "+invalidImplicits.head+" is not applicable here"+
- " because it comes after the application point and it lacks an explicit result type")
+ if (isSensibleAddendum)
+ s"\n Note: implicit $sym is not applicable here because it comes after the application point and it lacks an explicit result type"
+ else ""
+ )
+ }
}
best
diff --git a/test/files/neg/t7441.check b/test/files/neg/t7441.check
new file mode 100644
index 0000000000..f259457197
--- /dev/null
+++ b/test/files/neg/t7441.check
@@ -0,0 +1,6 @@
+t7441.scala:4: error: type mismatch;
+ found : Int(1)
+ required: List[Any]
+ def test = apply(1)
+ ^
+one error found
diff --git a/test/files/neg/t7441.scala b/test/files/neg/t7441.scala
new file mode 100644
index 0000000000..dad7421e3f
--- /dev/null
+++ b/test/files/neg/t7441.scala
@@ -0,0 +1,7 @@
+object Test {
+ object Bar {
+ def apply(xs: List[Any]): Int = 0
+ def test = apply(1)
+ }
+ implicit def foo = 1
+}