Skip to content

Divergence checker does not detect loop with higher-kinded type and by-name implicit #9568

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

Closed
smarter opened this issue Aug 14, 2020 · 1 comment

Comments

@smarter
Copy link
Member

smarter commented Aug 14, 2020

Minimized code

This is exactly the same code as #9504, but the implicit parameter has been marked as by-name:

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) // diverges
}

Expectation

It should behave like the non by-name case and error out immediately (this bug also affects #9523 where an existing testcase with a by-name implicit is not caught by the divergence checker anymore)

@smarter
Copy link
Member Author

smarter commented Aug 14, 2020

@odersky Do you think you could have a look at this one too?

smarter added a commit to dotty-staging/dotty that referenced this issue Aug 14, 2020
So far, like Scala 2, given:

  Either[Int, String] <:< ?F[String]

we were able to infer:

  ?F >: [X] =>> Either[Int, X]

However, in the inverse situation:

  ?F[String] <:< Either[Int, String]

Scala 2, but not Dotty, was able to infer:

  ?F <: [X] =>> Either[Int, X]

This commit fixes this by generalizing the partial unification logic to
be run both in `compareAppliedType2` and `compareAppliedType1`, this
broke a few tests:
- In `anykind.scala`, `kinder1` and `kinder2` became ambiguous, this is
  fixed by moving `kinder2` in a lower priority base trait.
- One of the implicit search in tests/neg/i3452.scala now goes into an
  infinite loop, I've disabled it for now. The issue seems to be related
  to by-name implicits as the divergence checker works when the by-name
  is removed from one of the implicit parameter, I've added the
  non-by-name version in the same file. I've also been able to reproduce the
  same symptoms on master and filed scala#9568.
odersky added a commit to dotty-staging/dotty that referenced this issue Aug 17, 2020
Require that the type that a by-name implicit can recursively implement
must be fully defined.
odersky added a commit to dotty-staging/dotty that referenced this issue Aug 17, 2020
Require that the type that a by-name implicit can recursively implement
must be fully defined.
odersky added a commit that referenced this issue Aug 17, 2020
Fix #9568: Disallow partially undefined types as byname anchors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant