@@ -3566,28 +3566,34 @@ class Typer extends Namer
3566
3566
/** Types the body Scala 2 macro declaration `def f = macro <body>` */
3567
3567
private def typedScala2MacroBody (call : untpd.Tree )(using Context ): Tree =
3568
3568
// TODO check that call is to a method with valid signature
3569
- def typedPrefix (tree : untpd.RefTree ): Tree = {
3569
+ def typedPrefix (tree : untpd.RefTree )( splice : Context ?=> Tree => Tree )( using Context ) : Tree = {
3570
3570
tryAlternatively {
3571
- typedExpr(tree, defn.AnyType )
3571
+ splice( typedExpr(tree, defn.AnyType ) )
3572
3572
} {
3573
3573
// Try to type as a macro bundle
3574
3574
val ref = tree match
3575
3575
case Ident (name) => untpd.Ident (name.toTypeName).withSpan(tree.span)
3576
3576
case Select (qual, name) => untpd.Select (qual, name.toTypeName).withSpan(tree.span)
3577
3577
val bundle = untpd.Apply (untpd.Select (untpd.New (ref), nme.CONSTRUCTOR ), untpd.Literal (Constant (null ))).withSpan(call.span)
3578
- typedExpr(bundle, defn.AnyType )
3578
+ val bundle1 = typedExpr(bundle, defn.AnyType )
3579
+ val bundleVal = SyntheticValDef (NameKinds .UniqueName .fresh(nme.bundle), bundle1).withSpan(call.span)
3580
+ tpd.Block (List (bundleVal), splice(tpd.ref(bundleVal.symbol))).withSpan(call.span)
3579
3581
}
3580
3582
}
3581
3583
if ctx.phase.isTyper then
3582
3584
call match
3583
3585
case call : untpd.Ident =>
3584
3586
typedIdent(call, defn.AnyType )
3585
3587
case untpd.Select (qual : untpd.RefTree , name) =>
3586
- val call2 = untpd.Select (untpd.TypedSplice (typedPrefix(qual)), name).withSpan(call.span)
3587
- typedSelect(call2, defn.AnyType )
3588
+ typedPrefix(qual) { qual =>
3589
+ val call2 = untpd.Select (untpd.TypedSplice (qual), name).withSpan(call.span)
3590
+ typedSelect(call2, defn.AnyType )
3591
+ }
3588
3592
case untpd.TypeApply (untpd.Select (qual : untpd.RefTree , name), targs) =>
3589
- val call2 = untpd.TypeApply (untpd.Select (untpd.TypedSplice (typedPrefix(qual)), name), targs).withSpan(call.span)
3590
- typedTypeApply(call2, defn.AnyType )
3593
+ typedPrefix(qual) { qual =>
3594
+ val call2 = untpd.TypeApply (untpd.Select (untpd.TypedSplice (qual), name), targs).withSpan(call.span)
3595
+ typedTypeApply(call2, defn.AnyType )
3596
+ }
3591
3597
case _ =>
3592
3598
ctx.error(" Invalid Scala 2 macro " + call.show, call.sourcePos)
3593
3599
EmptyTree
0 commit comments