Skip to content

Commit a447a7e

Browse files
committed
ByName trees
1 parent 80987df commit a447a7e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
428428
changePrec (GlobalPrec) {
429429
keywordStr("throw ") ~ toText(args.head)
430430
}
431-
else if fun.symbol == defn.byNameMethod && !printDebug then
431+
else if fun.symbol == defn.byNameMethod && !printDebug && !ctx.settings.YtestPickler.value then
432432
toText(args.head)
433433
else if (!printDebug && fun.hasType && fun.symbol == defn.QuotedRuntime_exprQuote)
434434
keywordStr("'{") ~ toTextGlobal(args, ", ") ~ keywordStr("}")

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ class TreeChecker extends Phase with SymTransformer {
222222
res
223223
}
224224

225+
val arguments: mutable.Set[untpd.Tree] = mutable.Set()
226+
private def withArgs[T](args: List[untpd.Tree])(op: => T): T =
227+
arguments ++= args
228+
val res = op
229+
arguments --= args
230+
res
231+
225232
def assertDefined(tree: untpd.Tree)(using Context): Unit =
226233
if (tree.symbol.maybeOwner.isTerm) {
227234
val sym = tree.symbol
@@ -446,6 +453,16 @@ class TreeChecker extends Phase with SymTransformer {
446453
typed(tree.expr, pt1)
447454
untpd.cpy.Typed(tree)(expr1, tpt1).withType(tree.typeOpt)
448455

456+
override def typedApply(tree: untpd.Apply, pt: Type)(using Context): Tree =
457+
if tree.fun.symbol == defn.byNameMethod then
458+
assert(arguments.contains(tree),
459+
i"unexpected <by-name> application $tree,\nwhich is not a method argument")
460+
ByName(typedUnadapted(tree.args.head, pt.widenByName))
461+
else
462+
withArgs(tree.args) {
463+
super.typedApply(tree, pt)
464+
}
465+
449466
private def checkOwner(tree: untpd.Tree)(using Context): Unit = {
450467
def ownerMatches(symOwner: Symbol, ctxOwner: Symbol): Boolean =
451468
symOwner == ctxOwner ||

0 commit comments

Comments
 (0)