Skip to content

Commit baba3f0

Browse files
Merge pull request #9265 from dotty-staging/fix-#9251
Fix #9251: Print applied lambda types directly
2 parents 6cbb458 + af344aa commit baba3f0

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

library/src/scala/tasty/reflect/SourceCodePrinter.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,10 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
11231123
case AppliedType(tp, args) =>
11241124
tp match {
11251125
case tp: TypeLambda =>
1126-
printType(tpe.dealias)
1126+
this += "("
1127+
printType(tp)
1128+
this += ")"
1129+
inSquare(printTypesOrBounds(args, ", "))
11271130
case tp: TypeRef if tp.typeSymbol == ctx.requiredClass("scala.<repeated>") =>
11281131
this += "_*"
11291132
case _ =>

tests/pos-macros/i9251/Macro_1.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cps
2+
3+
import scala.quoted._
4+
5+
trait CpsMonad[F[_]]
6+
7+
trait ComputationBound[T]
8+
9+
implicit object ComputationBoundMonad extends CpsMonad[ComputationBound]
10+
11+
inline def async[F[_]](using am:CpsMonad[F]): Async.InferAsyncArg[F] =
12+
new Async.InferAsyncArg[F]
13+
14+
object Async {
15+
16+
class InferAsyncArg[F[_]](using am:CpsMonad[F]) {
17+
inline def apply[T](inline expr: T):Unit = ${ Async.checkPrintTypeImpl[F,T]('expr) }
18+
}
19+
20+
21+
def checkPrintTypeImpl[F[_]:Type,T:Type](f: Expr[T])(using qctx: QuoteContext): Expr[Unit] =
22+
import qctx.tasty._
23+
24+
val fu = f.unseal
25+
fu match
26+
case Inlined(_,_,Block(_,Apply(TypeApply(Select(q,n),tparams),List(param)))) =>
27+
param.tpe match
28+
case AppliedType(tp,tparams1) =>
29+
val fType = summon[quoted.Type[F]]
30+
val ptp = tparams1.tail.head
31+
val ptpTree = Inferred(AppliedType(fType.unseal.tpe,List(ptp)))
32+
'{ println(${Expr(ptpTree.show)}) }
33+
34+
}

tests/pos-macros/i9251/Test_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package cps
2+
3+
val c = async[ComputationBound] {
4+
List(1,2,3,4).collectFirst { case x if x > 0 => x > 3 }
5+
}

0 commit comments

Comments
 (0)