Skip to content

Add regression test #11028

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
28 changes: 28 additions & 0 deletions tests/pos-macros/i9296/Macros_1.scala
Original file line number Diff line number Diff line change
@@ -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")
}

}
19 changes: 19 additions & 0 deletions tests/pos-macros/i9296/Test_2.scala
Original file line number Diff line number Diff line change
@@ -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)
}

}