Skip to content

Commit

Permalink
SI-7441 Don't ramble on about inapplicable implicits.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulp committed May 3, 2013
1 parent 98972c9 commit e86832d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/compiler/scala/tools/nsc/typechecker/Implicits.scala
Expand Up @@ -149,7 +149,7 @@ trait Implicits {
class SearchResult(val tree: Tree, val subst: TreeTypeSubstituter) { class SearchResult(val tree: Tree, val subst: TreeTypeSubstituter) {
override def toString = "SearchResult(%s, %s)".format(tree, override def toString = "SearchResult(%s, %s)".format(tree,
if (subst.isEmpty) "" else subst) if (subst.isEmpty) "" else subst)

def isFailure = false def isFailure = false
def isAmbiguousFailure = false def isAmbiguousFailure = false
final def isSuccess = !isFailure final def isSuccess = !isFailure
Expand All @@ -158,7 +158,7 @@ trait Implicits {
lazy val SearchFailure = new SearchResult(EmptyTree, EmptyTreeTypeSubstituter) { lazy val SearchFailure = new SearchResult(EmptyTree, EmptyTreeTypeSubstituter) {
override def isFailure = true override def isFailure = true
} }

lazy val AmbiguousSearchFailure = new SearchResult(EmptyTree, EmptyTreeTypeSubstituter) { lazy val AmbiguousSearchFailure = new SearchResult(EmptyTree, EmptyTreeTypeSubstituter) {
override def isFailure = true override def isFailure = true
override def isAmbiguousFailure = true override def isAmbiguousFailure = true
Expand Down Expand Up @@ -892,11 +892,20 @@ trait Implicits {
*/ */
if (divergence) if (divergence)
throw DivergentImplicit throw DivergentImplicit

else invalidImplicits take 1 foreach { sym =>
if (invalidImplicits.nonEmpty) 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, () => setAddendum(pos, () =>
"\n Note: implicit "+invalidImplicits.head+" is not applicable here"+ if (isSensibleAddendum)
" because it comes after the application point and it lacks an explicit result type") 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 best
Expand Down
6 changes: 6 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions 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
}

0 comments on commit e86832d

Please sign in to comment.