Skip to content

Add regression test #11029

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
Jan 7, 2021
Merged
Show file tree
Hide file tree
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
59 changes: 59 additions & 0 deletions tests/pos-macros/i9254/Macros_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cps

import scala.quoted._

trait CpsMonad[F[_]]

trait ComputationBound[T]

implicit object ComputationBoundMonad extends CpsMonad[ComputationBound]

inline def async[F[_]](using am:CpsMonad[F]): Async.InferAsyncArg[F] =
new Async.InferAsyncArg[F]

object PFHelper {
def create[X,Y](x:Boolean):PartialFunction[X,Y] = ???
}

object Async {

class InferAsyncArg[F[_]](using am:CpsMonad[F]) {

inline def apply[T](inline expr: T):Unit =
${
Async.transformImpl[F,T]('expr)
}

}

def transformImpl[F[_]:Type,T:Type](f: Expr[T])(using Quotes): Expr[Unit] =
import quotes.reflect._

def uninline(t:Term):Term =
t match
case Inlined(_,_,x) => uninline(x)
case _ => t

val fu = uninline(f.asTerm)
fu match
case Block(_,Apply(TypeApply(Select(q,n),tparams),List(param))) =>
param.tpe match
case AppliedType(tp,tparams1) =>
val fromTypeOrBounds = tparams1.head
val fromType = fromTypeOrBounds match
case bounds: TypeBounds => bounds.low
case tp: TypeRepr => tp
case np: NoPrefix => ???
val toType = tparams1.tail.head
val fType = TypeRepr.of[F]
val toWrapped = fType.appliedTo(toType)
val helper = '{ cps.PFHelper }.asTerm
val helperSelect = Select.unique(helper,"create")
val createPF = Apply(
TypeApply(helperSelect,List(Inferred(fromType),Inferred(toWrapped))),
List(Literal(BooleanConstant(true)))
)
val createPfApply = Apply(Select.unique(createPF,"apply"),List(Literal(IntConstant(1))))
Block(List(createPfApply),Literal(UnitConstant())).asExpr.asInstanceOf[Expr[Unit]]

}
5 changes: 5 additions & 0 deletions tests/pos-macros/i9254/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cps

val c = async[ComputationBound]{
List(1,2,3,4).collectFirst{ case x if x > 0 => x > 3 }
}