Skip to content

Turn mismatch given errors into given not found errors #8611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ class Definitions {
@tu lazy val Predef_undefined: Symbol = ScalaPredefModule.requiredMethod(nme.???)

def SubTypeClass(implicit ctx: Context): ClassSymbol = ctx.requiredClass("scala.<:<")
@tu lazy val SubType_refl: Symbol = SubTypeClass.companionModule.requiredMethod(nme.refl)

def DummyImplicitClass(implicit ctx: Context): ClassSymbol = ctx.requiredClass("scala.DummyImplicit")

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ object StdNames {
val productIterator: N = "productIterator"
val productPrefix: N = "productPrefix"
val raw_ : N = "raw"
val refl: N = "refl"
val reflect: N = "reflect"
val reflectiveSelectable: N = "reflectiveSelectable"
val reify : N = "reify"
Expand Down
14 changes: 9 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1407,11 +1407,15 @@ trait Implicits { self: Typer =>
}
if (ctx.reporter.hasErrors) {
ctx.reporter.removeBufferedMessages
SearchFailure {
adapted.tpe match {
case _: SearchFailureType => adapted
case _ => adapted.withType(new MismatchedImplicit(ref, pt, argument))
}
adapted.tpe match {
case _: SearchFailureType => SearchFailure(adapted)
case _ =>
// Special case for `$conforms` and `<:<.refl`. Showing them to the users brings
// no value, so we instead report a `NoMatchingImplicitsFailure`
if (adapted.symbol == defn.Predef_conforms || adapted.symbol == defn.SubType_refl)
NoMatchingImplicitsFailure
else
SearchFailure(adapted.withType(new MismatchedImplicit(ref, pt, argument)))
Copy link
Contributor Author

@julienrf julienrf Mar 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there are (and there were) no tests to exercise this code path.

}
}
else {
Expand Down
13 changes: 13 additions & 0 deletions tests/neg/implicitSearch.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Error: tests/neg/implicitSearch.scala:13:12 -------------------------------------------------------------------------
13 | sort(xs) // error (with a partially constructed implicit argument shown)
| ^
| no implicit argument of type Test.Ord[List[List[T]]] was found for parameter o of method sort in object Test.
| I found:
|
| Test.listOrd[T](Test.listOrd[T](/* missing */implicitly[Test.Ord[T]]))
|
| But no implicit values were found that match type Test.Ord[T].
-- Error: tests/neg/implicitSearch.scala:15:38 -------------------------------------------------------------------------
15 | listOrd(listOrd(implicitly[Ord[T]] /*not found*/)) // error
| ^
| no implicit argument of type Test.Ord[T] was found for parameter ev of method implicitly in object DottyPredef
2 changes: 0 additions & 2 deletions tests/neg/implicitSearch.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
object Test {

type T = String

class Ord[T]
implicit def listOrd[T](implicit o: Ord[T]): Ord[List[T]] = ???
implicit def intOrd: Ord[Int] = ???
Expand Down
14 changes: 14 additions & 0 deletions tests/neg/missing-implicit3.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Error: tests/neg/missing-implicit3.scala:13:36 ----------------------------------------------------------------------
13 |val sortedFoos = sort(List(new Foo)) // error
| ^
|no implicit argument of type ord.Ord[ord.Foo] was found for an implicit parameter of method sort in package ord.
|I found:
|
| ord.Ord.ordered[A](/* missing */implicitly[ord.Foo => Comparable[? >: ord.Foo]])
|
|But no implicit values were found that match type ord.Foo => Comparable[? >: ord.Foo].
|
|The following import might make progress towards fixing the problem:
|
| import ord.Ord.ordered
|
13 changes: 13 additions & 0 deletions tests/neg/missing-implicit3.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ord

trait Ord[A]

object Ord {
given ordered[A](using A => java.lang.Comparable[? >: A]) as Ord[A] = ???
}

def sort[A: Ord](as: List[A]): List[A] = ???

class Foo

val sortedFoos = sort(List(new Foo)) // error
14 changes: 2 additions & 12 deletions tests/neg/subtyping.check
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
-- Error: tests/neg/subtyping.scala:8:27 -------------------------------------------------------------------------------
8 | implicitly[B#X <:< A#X] // error: no implicit argument
| ^
| Cannot prove that B#X <:< A#X..
| I found:
|
| <:<.refl[Nothing]
|
| But method refl in object <:< does not match type B#X <:< A#X.
| Cannot prove that B#X <:< A#X.
-- Error: tests/neg/subtyping.scala:12:27 ------------------------------------------------------------------------------
12 | implicitly[a.T <:< a.U] // error: no implicit argument
| ^
| Cannot prove that a.T <:< a.U..
| I found:
|
| <:<.refl[Nothing]
|
| But method refl in object <:< does not match type a.T <:< a.U.
| Cannot prove that a.T <:< a.U.
4 changes: 4 additions & 0 deletions tests/neg/summon-function.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/summon-function.scala:2:23 -------------------------------------------------------------------------
2 | summon[Int => String] // error
| ^
| No implicit view available from Int => String.
3 changes: 3 additions & 0 deletions tests/neg/summon-function.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test {
summon[Int => String] // error
}