Skip to content

Commit 86fb551

Browse files
committed
Update SourceCodePrinter to new ContextualFunction syntax
1 parent 82dbb9e commit 86fb551

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

library/src/scala/tasty/Reflection.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
10151015
* of `Lambda`.
10161016
*/
10171017
object Lambda {
1018-
def unapply(tree: Tree)(using ctx: Context): Option[(List[ValDef], Term)] = tree match {
1018+
def unapply(tree: Block)(using ctx: Context): Option[(List[ValDef], Term)] = tree match {
10191019
case Block((ddef @ DefDef(_, _, params :: Nil, _, Some(body))) :: Nil, Closure(meth, _))
10201020
if ddef.symbol == meth.symbol =>
10211021
Some(params, body)

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package reflect
44
import scala.annotation.switch
55
import scala.quoted.show.SyntaxHighlight
66

7+
/** Printer for fully elaborated representation of the source code */
78
class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlight: SyntaxHighlight) extends Printer[R] {
89
import tasty.{_, given}
910
import syntaxHighlight._
@@ -382,18 +383,26 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
382383
this += "}"
383384

384385
case Apply(fn, args) =>
386+
var argsPrefix = ""
385387
fn match {
386388
case Select(This(_), "<init>") => this += "this" // call to constructor inside a constructor
387-
case Select(qual, "apply") if qual.tpe.isContextFunctionType =>
388-
printTree(qual) += " given "
389+
case Select(qual, "apply") =>
390+
if qual.tpe.isContextFunctionType then
391+
argsPrefix += "using "
392+
if qual.tpe.isErasedFunctionType then
393+
argsPrefix += "erased "
394+
printQualTree(fn)
389395
case _ => printQualTree(fn)
390396
}
391397
val args1 = args match {
392398
case init :+ Typed(Repeated(Nil, _), _) => init // drop empty var args at the end
393399
case _ => args
394400
}
395401

396-
inParens(printTrees(args1, ", "))
402+
inParens {
403+
this += argsPrefix
404+
printTrees(args1, ", ")
405+
}
397406

398407
case TypeApply(fn, args) =>
399408
printQualTree(fn)
@@ -446,10 +455,10 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
446455
this += " = "
447456
printTree(rhs)
448457

449-
case Lambda(params, body) => // must come before `Block`
458+
case tree @ Lambda(params, body) => // must come before `Block`
450459
inParens {
451460
printArgsDefs(params)
452-
this += " => "
461+
this += (if tree.tpe.isContextFunctionType then " ?=> " else " => ")
453462
printTree(body)
454463
}
455464

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
((qctx: scala.quoted.QuoteContext) => scala.internal.quoted.CompileTime.exprQuote[scala.Int](3) given (qctx))
1+
((qctx: scala.quoted.QuoteContext) ?=> scala.internal.quoted.CompileTime.exprQuote[scala.Int](3).apply(using qctx))
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
((qctx: scala.quoted.QuoteContext) => {
2-
val a: scala.quoted.Expr[scala.Int] = scala.internal.quoted.CompileTime.exprQuote[scala.Int](4) given (qctx)
3-
((qctx1_$1: scala.quoted.QuoteContext) => a) given (qctx)
1+
((qctx: scala.quoted.QuoteContext) ?=> {
2+
val a: scala.quoted.Expr[scala.Int] = scala.internal.quoted.CompileTime.exprQuote[scala.Int](4).apply(using qctx)
3+
((qctx1_$1: scala.quoted.QuoteContext) ?=> a).apply(using qctx)
44
})
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
((qctx: scala.quoted.QuoteContext) => {
2-
val a: scala.quoted.Expr[scala.Int] = scala.internal.quoted.CompileTime.exprQuote[scala.Int](4) given (qctx)
3-
((qctx2: scala.quoted.QuoteContext) => ((qctx1_$1: scala.quoted.QuoteContext) => a) given (qctx2)) given (qctx)
1+
((qctx: scala.quoted.QuoteContext) ?=> {
2+
val a: scala.quoted.Expr[scala.Int] = scala.internal.quoted.CompileTime.exprQuote[scala.Int](4).apply(using qctx)
3+
((qctx2: scala.quoted.QuoteContext) ?=> ((qctx1_$1: scala.quoted.QuoteContext) ?=> a).apply(using qctx2)).apply(using qctx)
44
})

0 commit comments

Comments
 (0)