Skip to content

Fix #9251: Print applied lambda types directly #9265

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
Jul 1, 2020
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
5 changes: 4 additions & 1 deletion library/src/scala/tasty/reflect/SourceCodePrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,10 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
case AppliedType(tp, args) =>
tp match {
case tp: TypeLambda =>
printType(tpe.dealias)
this += "("
printType(tp)
this += ")"
inSquare(printTypesOrBounds(args, ", "))
case tp: TypeRef if tp.typeSymbol == ctx.requiredClass("scala.<repeated>") =>
this += "_*"
case _ =>
Expand Down
34 changes: 34 additions & 0 deletions tests/pos-macros/i9251/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 Async {

class InferAsyncArg[F[_]](using am:CpsMonad[F]) {
inline def apply[T](inline expr: T):Unit = ${ Async.checkPrintTypeImpl[F,T]('expr) }
}


def checkPrintTypeImpl[F[_]:Type,T:Type](f: Expr[T])(using qctx: QuoteContext): Expr[Unit] =
import qctx.tasty._

val fu = f.unseal
fu match
case Inlined(_,_,Block(_,Apply(TypeApply(Select(q,n),tparams),List(param)))) =>
param.tpe match
case AppliedType(tp,tparams1) =>
val fType = summon[quoted.Type[F]]
val ptp = tparams1.tail.head
val ptpTree = Inferred(AppliedType(fType.unseal.tpe,List(ptp)))
'{ println(${Expr(ptpTree.show)}) }

}
5 changes: 5 additions & 0 deletions tests/pos-macros/i9251/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 }
}