Skip to content

Typer regression due to GADT changes #15920

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
WojciechMazur opened this issue Aug 26, 2022 · 1 comment
Closed

Typer regression due to GADT changes #15920

WojciechMazur opened this issue Aug 26, 2022 · 1 comment
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore

Comments

@WojciechMazur
Copy link
Contributor

Compiler version

Works in 3.1.3
Works in 3.2.0-RC4
Fails in 3.2.1 nighty builds

From bisect tool:

Last good release: 3.2.1-RC1-bin-20220711-6efd92d-NIGHTLY
First bad release: 3.2.1-RC1-bin-20220712-7e20b81-NIGHTLY

first bad commit 8b8ba7269eb317d0338141a9378d71600a2ba854 by @dwijnand

Minimized code

final class EitherIdOps[A](private val obj: A) extends AnyVal:
  def asLeft[B]: Either[A, B] = Left(obj)
  def asRight[B]: Either[B, A] = Right(obj)

object either:
  implicit final def catsSyntaxEitherId[A](a: A): EitherIdOps[A] = ???

trait ApplicativeError[F[_], E]
final class ApplicativeErrorOps[F[_], E, A](private val fa: F[A])
    extends AnyVal {
  def handleError(f: E => A): F[A] = ???
}
final def catsSyntaxApplicativeError[F[_], E, A](fa: F[A])(implicit
    F: ApplicativeError[F, E]
): ApplicativeErrorOps[F, E, A] = ???

object IO:
  case class Attempt[+A](ioa: IO[A]) extends IO[Either[Throwable, A]]
sealed abstract class IO[+A]:
  def attempt: IO[Either[Throwable, A]] = IO.Attempt(this)
  def syncStep: SyncIO[Either[IO[A], A]] = {
    def interpret[B](io: IO[B]): SyncIO[Either[IO[B], B]] =
      io match {
        case IO.Attempt(ioe) =>
          import either.given
          catsSyntaxApplicativeError {
            interpret(ioe)
              .map {
                case Left(io) => Left(io.attempt)
                case Right(a) => Right(a.asRight[Throwable])
              }
          }.handleError(t => Right(t.asLeft[IO[B]])) // error
      }

    interpret(this)
  }

object SyncIO:
  implicit def syncForSyncIO: ApplicativeError[SyncIO, Throwable] = ???

sealed abstract class SyncIO[+A]:
  def map[B](f: A => B): SyncIO[B] = ???

Output

Compiling project (Scala 3.2.1-RC1-bin-20220823-3ad97df-NIGHTLY, JVM)
[error] ./test.scala:32:36: Found:    Either[Throwable, IO[B]]
[error] Required: B
[error] 
[error] where:    B is a type in method interpret with bounds >: Either[Throwable, A$1]
[error]           }.handleError(t => Right(t.asLeft[IO[B]]))
[error]                                    ^^^^^^^^^^^^^^^

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug area:typer regression This worked in a previous version but doesn't anymore labels Aug 26, 2022
@WojciechMazur WojciechMazur changed the title Typer regression Typer regression due to GADT changes Aug 26, 2022
@dwijnand
Copy link
Member

Yeah, if you look at the rest of the PR there's associated the change to cats-effect, i.e. dotty-staging/cats-effect@3a32c0e so this isn't a regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

No branches or pull requests

2 participants