From 9c5a1457b65a03b8cab85058ba021ebab32fc2b0 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 11 Jul 2019 14:13:05 +0200 Subject: [PATCH] Fix #6281: Add full regression test Previously only the minimization was added as a test --- tests/run-with-compiler/i6281.scala | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/run-with-compiler/i6281.scala diff --git a/tests/run-with-compiler/i6281.scala b/tests/run-with-compiler/i6281.scala new file mode 100644 index 000000000000..1f329b658daf --- /dev/null +++ b/tests/run-with-compiler/i6281.scala @@ -0,0 +1,51 @@ +import scala.quoted._ + +object Test extends App { + + sealed trait HList + sealed trait HNil extends HList + sealed trait ::[E, T <: HList] extends HList + + type STM[A, L <: HList] = L match { + case HNil => Expr[A] + case e :: rs => (Expr[A] => STM[e, rs]) => STM[e, rs] + } + + type Stm[A, L <: HList] = L match { + case HNil => A + case e :: rs => (A => Stm[e, rs]) => Stm[e, rs] + } + + trait Effects[L <: HList] { + def reify[A] given Type[A]: STM[A, L] => Expr[Stm[A, L]] + def reflect[A] given Type[A]: Expr[Stm[A, L]] => STM[A, L] + } + delegate empty for Effects[HNil] { + def reify[A] given Type[A] = m => m + def reflect[A] given Type[A] = m => m + } + // for reify, we need type tags for E and also strangely for L. + implicit def cons [E, L <: HList] given Effects[L] given Type[E] given Type[L] given QuoteContext: Effects[E :: L] = new Effects[E :: L] { + def reify[A] given Type[A] = m => '{ k => ${ Effects[L].reify[E] { m( a => Effects[L].reflect[E]('k(a))) } }} + def reflect[A] given Type[A] = m => k => Effects[L].reflect[E] { m('{ a => ${ Effects[L].reify[E]( k('a)) } })} + } + def Effects[L <: HList] given Effects[L]: Effects[L] = the[Effects[L]] + + type RS = Boolean :: RS2 + type RS2 = Int :: String :: HNil + + def m given QuoteContext: STM[Int, RS] = k => k('{42}) + + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + + withQuoteContext { + println(Effects[RS].reify[Int] { m }.show) + + val effects = cons[Boolean, RS2] given (cons[Int, String :: HNil] given (cons[String, HNil] given empty)) + println(effects.reify[Int] { m }.show) + + val res : Expr[Stm[Int, RS]] = '{ k => ${ Effects[RS2].reify[Boolean] { m(a => Effects[RS2].reflect[Boolean]('k(a))) }}} + println(res.show) + } + +}