Skip to content

Commit

Permalink
Merge pull request scala#10611 from prolativ/no-implicit-view-message
Browse files Browse the repository at this point in the history
Fix scala#10603: implicitNotFound message for T <: Function1[_, _]

Don't display "No implicit view available ..." message when an given instance of a subtype of Function1 was not found
  • Loading branch information
prolativ authored Dec 3, 2020
2 parents 04737b5 + 84b0627 commit edfb179
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ class ImplicitSearchError(
*/
private def userDefinedImplicitNotFoundTypeMessage: Option[String] =
pt.baseClasses.iterator
// Don't inherit "No implicit view available..." message if subtypes of Function1 are not treated as implicit conversions anymore
.filter(sym => Feature.migrateTo3 || sym != defn.Function1)
.map(userDefinedImplicitNotFoundTypeMessage(_))
.find(_.isDefined).flatten

Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i10603a.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/i10603a.scala:2:35 ---------------------------------------------------------------------------------
2 | val x = implicitly[List[Boolean]] // error
| ^
| no implicit argument of type List[Boolean] was found for parameter e of method implicitly in object Predef
3 changes: 3 additions & 0 deletions tests/neg/i10603a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test {
val x = implicitly[List[Boolean]] // error
}
4 changes: 4 additions & 0 deletions tests/neg/i10603b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/i10603b.scala:4:35 ---------------------------------------------------------------------------------
4 | val x = implicitly[List[Boolean]] // error
| ^
| No implicit view available from Int => Boolean.
5 changes: 5 additions & 0 deletions tests/neg/i10603b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import language.`3.0-migration`

object Test {
val x = implicitly[List[Boolean]] // error
}
2 changes: 1 addition & 1 deletion tests/neg/summon-function.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Error: tests/neg/summon-function.scala:2:23 -------------------------------------------------------------------------
2 | summon[Int => String] // error
| ^
| No implicit view available from Int => String.
| no implicit argument of type Int => String was found for parameter x of method summon in object Predef

0 comments on commit edfb179

Please sign in to comment.