diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 85bbafdc3426..44995dddda5c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -247,11 +247,9 @@ object Implicits: candidates += Candidate(ref, ckind, level) if considerExtension then - val tryExtension = tryCandidate(extensionOnly = true) - companionRefs.foreach(tryExtension) + companionRefs.foreach(tryCandidate(extensionOnly = true)) if refs.nonEmpty then - val tryGiven = tryCandidate(extensionOnly = false) - refs.foreach(tryGiven) + refs.foreach(tryCandidate(extensionOnly = false)) candidates.toList } } @@ -1373,6 +1371,7 @@ trait Implicits: if cand1.ref eq cand.ref then lazy val wildTp = wildApprox(tp.widenExpr) if belowByname && (wildTp <:< wildPt) then + fullyDefinedType(tp, "by-name implicit parameter", span) false else if prev.typeSize > ptSize || prev.coveringSet != ptCoveringSet then loop(outer, tp.isByName || belowByname) diff --git a/tests/neg/i3452.scala b/tests/neg/i3452.scala index 1a439338f4d6..29a7d4b19219 100644 --- a/tests/neg/i3452.scala +++ b/tests/neg/i3452.scala @@ -6,9 +6,7 @@ object Test { implicit def case1[F[_]](implicit t: => TC[F[Any]]): TC[Tuple2K[[_] =>> Any, F, Any]] = ??? implicit def case2[A, F[_]](implicit r: TC[F[Any]]): TC[A] = ??? - // Disabled because it leads to an infinite loop in implicit search - // this is probably the same issue as https://github.com/lampepfl/dotty/issues/9568 - // implicitly[TC[Int]] // was: error + implicitly[TC[Int]] // typechecks because we infer F := Nothing (should we avoid inferring Nothing for higher-kinded types?) } object Test1 { diff --git a/tests/neg/i9568.check b/tests/neg/i9568.check new file mode 100644 index 000000000000..cb7e37ed5415 --- /dev/null +++ b/tests/neg/i9568.check @@ -0,0 +1,9 @@ +-- Error: tests/neg/i9568.scala:13:10 ---------------------------------------------------------------------------------- +13 | blaMonad.foo(bla) // error: diverges + | ^ + |no implicit argument of type => Monad[([_$3] =>> Any)] was found for parameter ev of method blaMonad in object Test. + |I found: + | + | Test.blaMonad[Nothing, S](Test.blaMonad[F, S]) + | + |But method blaMonad in object Test does not match type => Monad[Nothing]. diff --git a/tests/neg/i9568.scala b/tests/neg/i9568.scala new file mode 100644 index 000000000000..6fc9ba35a9fb --- /dev/null +++ b/tests/neg/i9568.scala @@ -0,0 +1,14 @@ +trait Monad[F[_]] { + def foo[A](fa: F[A]): Unit = {} +} + +class Bla[F[_], A] + +object Test { + type Id[A] = A + + val bla: Bla[Id, Unit] = ??? + implicit def blaMonad[F[_], S](implicit ev: => Monad[F]): Monad[({type L[X] = Bla[F, X]})#L] = ??? + + blaMonad.foo(bla) // error: diverges +} \ No newline at end of file diff --git a/tests/pos/i9568.scala b/tests/pos/i9568.scala new file mode 100644 index 000000000000..4b4a5843ab4f --- /dev/null +++ b/tests/pos/i9568.scala @@ -0,0 +1,25 @@ +trait Monad[F[_]] { + def foo[A](fa: F[A]): Unit = {} +} + +class Bla[F[_], A] + +object Test1 { + type Id[A] = A + + val bla: Bla[Id, Unit] = ??? + implicit def blaMonad[F[_]: Monad, S]: Monad[({type L[X] = Bla[F, X]})#L] = ??? + implicit def idMonad: Monad[Id] = ??? + + blaMonad.foo(bla) // does not diverge +} + +object Test2 { + type Id[A] = A + + val bla: Bla[Id, Unit] = ??? + implicit def blaMonad[F[_], S](implicit ev: => Monad[F]): Monad[({type L[X] = Bla[F, X]})#L] = ??? + implicit def idMonad: Monad[Id] = ??? + + blaMonad.foo(bla) // does not diverge +}