diff --git a/tests/pos-macros/i9296/Macros_1.scala b/tests/pos-macros/i9296/Macros_1.scala new file mode 100644 index 000000000000..240cd97eabae --- /dev/null +++ b/tests/pos-macros/i9296/Macros_1.scala @@ -0,0 +1,28 @@ +package a + +import scala.quoted._ +import scala.concurrent._ + +object M { + + inline def resolveInMacros[F[_],T](f: Future[T]):Conversion[Future[T],F[T]] = + ${ resolveInMacrosImpl[F,T]('f) } + + def resolveInMacrosImpl[F[_]:Type,T:Type](f:Expr[Future[T]])(using qctx:Quotes):Expr[ + Conversion[Future[T],F[T]]]={ + import quotes.reflect._ + val conversion = TypeIdent(Symbol.classSymbol("scala.Conversion")).tpe + val inFuture = f.asTerm.tpe.widen + val tType = TypeRepr.of[T] + val fType = TypeRepr.of[F] + val inCB = fType.appliedTo(tType).simplified + val taConversion = conversion.appliedTo(List(inFuture, inCB)) + Implicits.search(taConversion) match + case implSuccess: ImplicitSearchSuccess => + implSuccess.tree.asExpr.asInstanceOf[Expr[Conversion[Future[T],F[T]]]] + case implFailure: ImplicitSearchFailure => + println(s"searchFailure: ${implFailure.explanation}") + throw new RuntimeException("implicit search failed") + } + +} diff --git a/tests/pos-macros/i9296/Test_2.scala b/tests/pos-macros/i9296/Test_2.scala new file mode 100644 index 000000000000..8e22c5ae841b --- /dev/null +++ b/tests/pos-macros/i9296/Test_2.scala @@ -0,0 +1,19 @@ +package a + +import scala.language.implicitConversions +import scala.concurrent._ + +trait CB[T] + +given myConversion[T]: Conversion[Future[T],CB[T]] = (ft => ???) + +object O { + + def main(argvs: Array[String]): Unit = { + val p = Promise[Int]() + //val cbp = summon[Conversion[Future[Int],CB[Int]]] //works + val cbp = M.resolveInMacros[CB,Int](p.future) + val x = cbp(p.future) + } + +}