diff --git a/community-build/community-projects/dotty-cps-async b/community-build/community-projects/dotty-cps-async index d7f4a49916d1..ae2276432b15 160000 --- a/community-build/community-projects/dotty-cps-async +++ b/community-build/community-projects/dotty-cps-async @@ -1 +1 @@ -Subproject commit d7f4a49916d1a53be5587e0d76dae05ee6435676 +Subproject commit ae2276432b158e1b42fb1941d79cd864dde78194 diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 3789c12c0d2a..4ac48335afa7 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -1239,7 +1239,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { case res: Apply if res.symbol == defn.InternalQuoted_exprSplice && level == 0 && !suppressInline => - expandMacro(res.args.head, tree.span) + val expanded = expandMacro(res.args.head, tree.span) + typedExpr(expanded) // Inline calls and constant fold code generated by the macro case res => res } diff --git a/tests/pos-macros/i8866/Macro_1.scala b/tests/pos-macros/i8866/Macro_1.scala new file mode 100644 index 000000000000..6f87ba398729 --- /dev/null +++ b/tests/pos-macros/i8866/Macro_1.scala @@ -0,0 +1,27 @@ +import scala.quoted._ + +object OtherMacro { + + def impl(using qctx: QuoteContext): Expr[Int] = + '{ 42 } + + inline def apply = ${ OtherMacro.impl } + +} + +object Macro { + + def impl(using qctx: QuoteContext): Expr[Int] = { + import qctx.tasty._ + + let( + Select.unique( + '{ OtherMacro }.unseal, + "apply" + ) + )(identity).seal.cast[Int] + } + + inline def apply = ${ Macro.impl } + +} diff --git a/tests/pos-macros/i8866/Test_2.scala b/tests/pos-macros/i8866/Test_2.scala new file mode 100644 index 000000000000..574844d6b243 --- /dev/null +++ b/tests/pos-macros/i8866/Test_2.scala @@ -0,0 +1 @@ +val a = Macro.apply diff --git a/tests/pos-macros/i8866b/Macro_1.scala b/tests/pos-macros/i8866b/Macro_1.scala new file mode 100644 index 000000000000..f6b2a60fa9fa --- /dev/null +++ b/tests/pos-macros/i8866b/Macro_1.scala @@ -0,0 +1,23 @@ +import scala.quoted._ + +object Other { + inline def apply = 5 +} + +object Macro { + + def impl(using qctx: QuoteContext): Expr[Int] = { + import qctx.tasty._ + + let( + Select.unique( + '{ Other }.unseal, + "apply" + ) + )(identity).seal.cast[Int] + + } + + inline def apply = ${ Macro.impl } + +} diff --git a/tests/pos-macros/i8866b/Test_2.scala b/tests/pos-macros/i8866b/Test_2.scala new file mode 100644 index 000000000000..574844d6b243 --- /dev/null +++ b/tests/pos-macros/i8866b/Test_2.scala @@ -0,0 +1 @@ +val a = Macro.apply diff --git a/tests/pos-macros/i8866c/Macro_1.scala b/tests/pos-macros/i8866c/Macro_1.scala new file mode 100644 index 000000000000..4e2cd585ea95 --- /dev/null +++ b/tests/pos-macros/i8866c/Macro_1.scala @@ -0,0 +1,12 @@ +import scala.quoted._ + +def f(xs: Boolean*): Unit = ??? + +def mcrImpl(using QuoteContext): Expr[Unit] = + val func: Expr[Seq[Boolean] => Unit] = + '{(esx: Seq[Boolean]) => f(esx: _*)} + val trees: Expr[Seq[Boolean]] = '{Seq(true)} + Expr.betaReduce('{ $func($trees) }) +end mcrImpl + +inline def mcr: Unit = ${ mcrImpl } diff --git a/tests/pos-macros/i8866c/Test_2.scala b/tests/pos-macros/i8866c/Test_2.scala new file mode 100644 index 000000000000..660bfc15d149 --- /dev/null +++ b/tests/pos-macros/i8866c/Test_2.scala @@ -0,0 +1 @@ +val x = mcr diff --git a/tests/pos-macros/i9687/Macro_1.scala b/tests/pos-macros/i9687/Macro_1.scala new file mode 100644 index 000000000000..37a417eb7283 --- /dev/null +++ b/tests/pos-macros/i9687/Macro_1.scala @@ -0,0 +1,44 @@ +package x + +import scala.quoted._ + +object FastPath { + + inline def sum(x:Int):Int = + x + 1 + +} + +object SlowPath { + + def sum(x:Int):Int = + x + 1 + +} + +object X { + + inline def transform[A](inline x:A):A = ${ + transformImpl[A]('x) + } + + def transformImpl[A:Type](x:Expr[A])(using qctx: QuoteContext):Expr[A] = { + import qctx.tasty._ + val slowPath = '{ SlowPath }.unseal + val fastPath = '{ FastPath }.unseal + val transformer = new TreeMap() { + override def transformTerm(term:Term)(using ctx:Context):Term = { + term match + case Apply(sel@Select(o,m),args) => + if ( o.tpe =:= slowPath.tpe && m=="sum" ) + Apply(Select.unique(fastPath,"sum"), args) + else + super.transformTerm(term) + case _ => super.transformTerm(term) + } + } + val r = transformer.transformTerm(x.unseal).seal.cast[A] + s"result: ${r.show}" + r + } +} diff --git a/tests/pos-macros/i9687/Test_2.scala b/tests/pos-macros/i9687/Test_2.scala new file mode 100644 index 000000000000..5b0725adcee1 --- /dev/null +++ b/tests/pos-macros/i9687/Test_2.scala @@ -0,0 +1,12 @@ +package x + + +object Main { + + + def main(args:Array[String]):Unit = + val r = X.transform{ + SlowPath.sum(1) + } + +}