From 571281d0496311d02785b1189dcd530f3f595f76 Mon Sep 17 00:00:00 2001 From: odersky Date: Thu, 7 Apr 2022 11:30:29 +0200 Subject: [PATCH] More regression tests Closes #9287 Closes #12640 Closes #12896 --- tests/neg/i12640.scala | 17 +++++++++++++++++ tests/neg/i9287.scala | 7 +++++++ tests/pos/i12896.scala | 12 ++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/neg/i12640.scala create mode 100644 tests/neg/i9287.scala create mode 100644 tests/pos/i12896.scala diff --git a/tests/neg/i12640.scala b/tests/neg/i12640.scala new file mode 100644 index 000000000000..3dc302d9d316 --- /dev/null +++ b/tests/neg/i12640.scala @@ -0,0 +1,17 @@ +package x + +trait CpsMonad[F[_]]: + def pure[A](x:A): F[A] + def flatMap[A,B](fa:F[A])(f: A=>F[B]): F[B] + +abstract sealed class CpsStream[-F[_],+T] + +case class Cons[F[_],T](head:T, tailFun: ()=>F[CpsStream[F,T]]) extends CpsStream[F,T] + +case class Empty[F[_]]() extends CpsStream[F,Nothing] + +def unfold[S,F[_]:CpsMonad,T](s0:S)(f:S => F[Option[(S,T)]]):F[CpsStream[F,T]] = + summon[CpsMonad[F]].flatMap(f(s0)){ + case Some(s1,a) => Cons(a, () => unfold(s1,f)) // error (used to crash) + case None => summon[CpsMonad[F]].pure(Empty[F]()) + } \ No newline at end of file diff --git a/tests/neg/i9287.scala b/tests/neg/i9287.scala new file mode 100644 index 000000000000..21240008f908 --- /dev/null +++ b/tests/neg/i9287.scala @@ -0,0 +1,7 @@ +object Foo { + Nil { + class i0 { a: i2 => // error + class i1 + } + } // error +} \ No newline at end of file diff --git a/tests/pos/i12896.scala b/tests/pos/i12896.scala new file mode 100644 index 000000000000..6ce996b2306f --- /dev/null +++ b/tests/pos/i12896.scala @@ -0,0 +1,12 @@ +trait IO[E] { + def map[B](f: Any => B): IO[E] = ??? + def flatMap[C](f: Any => IO[C]): IO[E | C] = ??? +} + +class Test { + def test: Unit = { + val a: IO[Nothing] = ??? + + val d = a.flatMap(y => a.flatMap(z => a.map(_ => z))) + } +} \ No newline at end of file