@@ -3492,15 +3492,31 @@ class Typer extends Namer
3492
3492
/** Types the body Scala 2 macro declaration `def f = macro <body>` */
3493
3493
private def typedScala2MacroBody (call : untpd.Tree )(using Context ): Tree =
3494
3494
// TODO check that call is to a method with valid signature
3495
- call match
3496
- case rhs0 : untpd.Ident =>
3497
- typedIdent(rhs0, defn.AnyType )
3498
- case rhs0 : untpd.Select =>
3499
- typedSelect(rhs0, defn.AnyType )
3500
- case rhs0 : untpd.TypeApply =>
3501
- typedTypeApply(rhs0, defn.AnyType )
3502
- case _ =>
3503
- ctx.error(" Invalid Scala 2 macro" , call.sourcePos)
3504
- EmptyTree
3495
+ def typedPrefix (tree : untpd.RefTree ): Tree = {
3496
+ tryAlternatively {
3497
+ typedExpr(tree, defn.AnyType )
3498
+ } {
3499
+ // Try to type as a macro bundle
3500
+ val ref = tree match
3501
+ case Ident (name) => untpd.Ident (name.toTypeName).withSpan(tree.span)
3502
+ case Select (qual, name) => untpd.Select (qual, name.toTypeName).withSpan(tree.span)
3503
+ val bundle = untpd.Apply (untpd.Select (untpd.New (ref), nme.CONSTRUCTOR ), untpd.Literal (Constant (null ))).withSpan(call.span)
3504
+ typedExpr(bundle, defn.AnyType )
3505
+ }
3506
+ }
3507
+ if ctx.phase.isTyper then
3508
+ call match
3509
+ case call : untpd.Ident =>
3510
+ typedIdent(call, defn.AnyType )
3511
+ case untpd.Select (qual : untpd.RefTree , name) =>
3512
+ val call2 = untpd.Select (untpd.TypedSplice (typedPrefix(qual)), name).withSpan(call.span)
3513
+ typedSelect(call2, defn.AnyType )
3514
+ case untpd.TypeApply (untpd.Select (qual : untpd.RefTree , name), targs) =>
3515
+ val call2 = untpd.TypeApply (untpd.Select (untpd.TypedSplice (typedPrefix(qual)), name), targs).withSpan(call.span)
3516
+ typedTypeApply(call2, defn.AnyType )
3517
+ case _ =>
3518
+ ctx.error(" Invalid Scala 2 macro " + call.show, call.sourcePos)
3519
+ EmptyTree
3520
+ else typedExpr(call, defn.AnyType )
3505
3521
3506
3522
}
0 commit comments