Skip to content

Fix #6281: Add full regression test #6840

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

Merged
merged 1 commit into from
Jul 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions tests/run-with-compiler/i6281.scala
Original file line number Diff line number Diff line change
@@ -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)
}

}