Skip to content

Type inference regression with type bounds #8031

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
adamgfraser opened this issue Jan 18, 2020 · 0 comments
Closed

Type inference regression with type bounds #8031

adamgfraser opened this issue Jan 18, 2020 · 0 comments

Comments

@adamgfraser
Copy link
Contributor

Following up on #7965 we resolved the assertion error but are still seeing some regressions in type inference versus Scala 2. Relatively minimized example below.

minimized code

object Example extends App {

  trait Has[A]

  trait ZIO[-R] {
    def provideLayer[R0, R1 <: Has[_]](
        layer: ZLayer[R0, R1]
    )(implicit ev: R1 <:< R): ZIO[R0] =
      ???
  }

  trait ZLayer[-RIn, +ROut <: Has[_]] {
    def ++[RIn2, ROut1 >: ROut <: Has[_], ROut2 <: Has[_]](
        that: ZLayer[RIn2, ROut2]
    ): ZLayer[RIn with RIn2, ROut1 with ROut2] = ???
  }

  trait RandomService
  trait SizedService

  type Random = Has[RandomService]
  type Sized = Has[SizedService]

  def random: ZLayer[Random, Random] = ???
  def sized: ZLayer[Any, Sized] = ???

  lazy val zio: ZIO[Random with Sized] = ???

  // Okay on Scala 2, does not compile on Dotty
  lazy val eliminated: ZIO[Random] =
    zio.provideLayer(random ++ sized)

  // Compiles on Dotty with an explicit type annotation
  lazy val eliminated2: ZIO[Random] =
    zio.provideLayer[Random, Random with Sized](random ++ sized)

  println("It compiles!")
}

https://scastie.scala-lang.org/q88sfaKXTmiTJ6Iu1umiqw

Compilation output
Cannot prove that Example.Has[?
   >: Example.RandomService & Example.SizedService <: Example.RandomService | 
    Example.SizedService
] <:< Example.Random & Example.Sized..
I found:

    <:<.refl[Nothing]

But method refl in object <:< does not match type Example.Has[?
   >: Example.RandomService & Example.SizedService <: Example.RandomService | 
    Example.SizedService
] <:< (Example.Random & Example.Sized).

expectation

I would have expected this to compile without an explicit type annotation as it does on Scala 2.

Copying @jdegoes.

@abgruszecki abgruszecki changed the title Type inference issue with type bounds Type inference regression with type bounds Jan 20, 2020
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

3 participants