Skip to content

Commit 73177bc

Browse files
committed
splice selection into block
1 parent 5beb624 commit 73177bc

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,9 +3565,9 @@ class Typer extends Namer
35653565
/** Types the body Scala 2 macro declaration `def f = macro <body>` */
35663566
private def typedScala2MacroBody(call: untpd.Tree)(using Context): Tree =
35673567
// TODO check that call is to a method with valid signature
3568-
def typedPrefix(tree: untpd.RefTree): Tree = {
3568+
def typedPrefix(tree: untpd.RefTree)(splice: Context ?=> Tree => Tree)(using Context): Tree = {
35693569
tryAlternatively {
3570-
typedExpr(tree, defn.AnyType)
3570+
splice(typedExpr(tree, defn.AnyType))
35713571
} {
35723572
// Try to type as a macro bundle
35733573
val ref = tree match
@@ -3576,19 +3576,23 @@ class Typer extends Namer
35763576
val bundle = untpd.Apply(untpd.Select(untpd.New(ref), nme.CONSTRUCTOR), untpd.Literal(Constant(null))).withSpan(call.span)
35773577
val bundle1 = typedExpr(bundle, defn.AnyType)
35783578
val bundleVal = SyntheticValDef(NameKinds.UniqueName.fresh("bundle".toTermName), bundle1)
3579-
tpd.Block(List(bundleVal), tpd.ref(bundleVal.symbol))
3579+
tpd.Block(List(bundleVal), splice(tpd.ref(bundleVal.symbol)))
35803580
}
35813581
}
35823582
if ctx.phase.isTyper then
35833583
call match
35843584
case call: untpd.Ident =>
35853585
typedIdent(call, defn.AnyType)
35863586
case untpd.Select(qual: untpd.RefTree, name) =>
3587-
val call2 = untpd.Select(untpd.TypedSplice(typedPrefix(qual)), name).withSpan(call.span)
3588-
typedSelect(call2, defn.AnyType)
3587+
typedPrefix(qual) { qual =>
3588+
val call2 = untpd.Select(untpd.TypedSplice(qual), name).withSpan(call.span)
3589+
typedSelect(call2, defn.AnyType)
3590+
}
35893591
case untpd.TypeApply(untpd.Select(qual: untpd.RefTree, name), targs) =>
3590-
val call2= untpd.TypeApply(untpd.Select(untpd.TypedSplice(typedPrefix(qual)), name), targs).withSpan(call.span)
3591-
typedTypeApply(call2, defn.AnyType)
3592+
typedPrefix(qual) { qual =>
3593+
val call2= untpd.TypeApply(untpd.Select(untpd.TypedSplice(qual), name), targs).withSpan(call.span)
3594+
typedTypeApply(call2, defn.AnyType)
3595+
}
35923596
case _ =>
35933597
ctx.error("Invalid Scala 2 macro " + call.show, call.sourcePos)
35943598
EmptyTree

0 commit comments

Comments
 (0)