Skip to content

Commit 316dc83

Browse files
Merge pull request #11028 from dotty-staging/fix-#9296
Add regression test
2 parents 6124562 + e877a76 commit 316dc83

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

tests/pos-macros/i9296/Macros_1.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package a
2+
3+
import scala.quoted._
4+
import scala.concurrent._
5+
6+
object M {
7+
8+
inline def resolveInMacros[F[_],T](f: Future[T]):Conversion[Future[T],F[T]] =
9+
${ resolveInMacrosImpl[F,T]('f) }
10+
11+
def resolveInMacrosImpl[F[_]:Type,T:Type](f:Expr[Future[T]])(using qctx:Quotes):Expr[
12+
Conversion[Future[T],F[T]]]={
13+
import quotes.reflect._
14+
val conversion = TypeIdent(Symbol.classSymbol("scala.Conversion")).tpe
15+
val inFuture = f.asTerm.tpe.widen
16+
val tType = TypeRepr.of[T]
17+
val fType = TypeRepr.of[F]
18+
val inCB = fType.appliedTo(tType).simplified
19+
val taConversion = conversion.appliedTo(List(inFuture, inCB))
20+
Implicits.search(taConversion) match
21+
case implSuccess: ImplicitSearchSuccess =>
22+
implSuccess.tree.asExpr.asInstanceOf[Expr[Conversion[Future[T],F[T]]]]
23+
case implFailure: ImplicitSearchFailure =>
24+
println(s"searchFailure: ${implFailure.explanation}")
25+
throw new RuntimeException("implicit search failed")
26+
}
27+
28+
}

tests/pos-macros/i9296/Test_2.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package a
2+
3+
import scala.language.implicitConversions
4+
import scala.concurrent._
5+
6+
trait CB[T]
7+
8+
given myConversion[T]: Conversion[Future[T],CB[T]] = (ft => ???)
9+
10+
object O {
11+
12+
def main(argvs: Array[String]): Unit = {
13+
val p = Promise[Int]()
14+
//val cbp = summon[Conversion[Future[Int],CB[Int]]] //works
15+
val cbp = M.resolveInMacros[CB,Int](p.future)
16+
val x = cbp(p.future)
17+
}
18+
19+
}

0 commit comments

Comments
 (0)