From f8d9c18f5105bc839435b8e19a4e0896bb91b0fa Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Wed, 24 Jul 2024 10:09:09 +0200 Subject: [PATCH] Add regression test for #21215 fixed in #21226 --- tests/pos/i21215.scala | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/pos/i21215.scala diff --git a/tests/pos/i21215.scala b/tests/pos/i21215.scala new file mode 100644 index 000000000000..e810051da7b7 --- /dev/null +++ b/tests/pos/i21215.scala @@ -0,0 +1,45 @@ + +trait FlatMap[F[_]]: + def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B] = ??? + def ifM[B](ifTrue: => F[B], ifFalse: => F[B])(implicit F: FlatMap[F]): F[B] = ??? +trait Monad[F[_]] extends FlatMap[F] +trait MonadError[F[_], E] extends Monad[F]: + def raiseError[A](e: E): F[A] +trait Temporal[F[_]] extends MonadError[F, Throwable] + +trait FlatMapOps[F[_], A]: + def flatMap[B](f: A => F[B]): F[B] = ??? + def map[B](f: A => B): F[B] = ??? + def ifM[B](ifTrue: => F[B], ifFalse: => F[B])(implicit F: FlatMap[F]): F[B] = ??? + +implicit def toFlatMapOps[F[_], A](target: F[A])(implicit tc: FlatMap[F]): FlatMapOps[F, A] = ??? + +abstract class Ref[F[_], A] +object Ref: + final class ApplyBuilders[F[_]]: + def of[A](a: A): F[Ref[F, A]] = ??? + def apply[F[_]]: ApplyBuilders[F] = ??? + +trait DatabaseMetaData[F[_]] +class DatabaseMetaDataImpl[F[_]]( + statementClosed: Ref[F, Boolean], + resultSetClosed: Ref[F, Boolean] + ) extends DatabaseMetaData[F] + +trait LdbcConnection[F[_]]: + def getMetaData(): F[DatabaseMetaData[F]] + +class ConnectionImpl[F[_]: Temporal](using ev: MonadError[F, Throwable]) + extends LdbcConnection[F]: + def isClosed(): F[Boolean] = ??? + override def getMetaData(): F[DatabaseMetaData[F]] = + isClosed().ifM( + ev.raiseError(???), + (for + statementClosed <- Ref[F].of[Boolean](false) + resultSetClosed <- Ref[F].of[Boolean](false) + yield DatabaseMetaDataImpl[F]( + statementClosed, + resultSetClosed + )) + )