Skip to content

Commit

Permalink
Add regression test for scala#21215 fixed in scala#21226
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneFlesselle committed Jul 24, 2024
1 parent 46ff151 commit 6e1ae14
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/neg/i21215.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

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 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) // error
yield DatabaseMetaDataImpl[F](
statementClosed,
resultSetClosed
))
)

0 comments on commit 6e1ae14

Please sign in to comment.