@@ -3446,15 +3446,31 @@ class Typer extends Namer
3446
3446
/** Types the body Scala 2 macro declaration `def f = macro <body>` */
3447
3447
private def typedScala2MacroBody (call : untpd.Tree )(using Context ): Tree =
3448
3448
// TODO check that call is to a method with valid signature
3449
- call match
3450
- case rhs0 : untpd.Ident =>
3451
- typedIdent(rhs0, defn.AnyType )
3452
- case rhs0 : untpd.Select =>
3453
- typedSelect(rhs0, defn.AnyType )
3454
- case rhs0 : untpd.TypeApply =>
3455
- typedTypeApply(rhs0, defn.AnyType )
3456
- case _ =>
3457
- ctx.error(" Invalid Scala 2 macro" , call.sourcePos)
3458
- EmptyTree
3449
+ def typedPrefix (tree : untpd.RefTree ): Tree = {
3450
+ tryAlternatively {
3451
+ typedExpr(tree, defn.AnyType )
3452
+ } {
3453
+ // Try to type as a macro bundle
3454
+ val ref = tree match
3455
+ case Ident (name) => untpd.Ident (name.toTypeName).withSpan(tree.span)
3456
+ case Select (qual, name) => untpd.Select (qual, name.toTypeName).withSpan(tree.span)
3457
+ val bundle = untpd.Apply (untpd.Select (untpd.New (ref), nme.CONSTRUCTOR ), untpd.Literal (Constant (null ))).withSpan(call.span)
3458
+ typedExpr(bundle, defn.AnyType )
3459
+ }
3460
+ }
3461
+ if ctx.phase.isTyper then
3462
+ call match
3463
+ case call : untpd.Ident =>
3464
+ typedIdent(call, defn.AnyType )
3465
+ case untpd.Select (qual : untpd.RefTree , name) =>
3466
+ val call2 = untpd.Select (untpd.TypedSplice (typedPrefix(qual)), name).withSpan(call.span)
3467
+ typedSelect(call2, defn.AnyType )
3468
+ case untpd.TypeApply (untpd.Select (qual : untpd.RefTree , name), targs) =>
3469
+ val call2 = untpd.TypeApply (untpd.Select (untpd.TypedSplice (typedPrefix(qual)), name), targs).withSpan(call.span)
3470
+ typedTypeApply(call2, defn.AnyType )
3471
+ case _ =>
3472
+ ctx.error(" Invalid Scala 2 macro " + call.show, call.sourcePos)
3473
+ EmptyTree
3474
+ else typedExpr(call, defn.AnyType )
3459
3475
3460
3476
}
0 commit comments