diff --git a/community-build/community-projects/Monocle b/community-build/community-projects/Monocle index 4613afff874c..bc5781caf523 160000 --- a/community-build/community-projects/Monocle +++ b/community-build/community-projects/Monocle @@ -1 +1 @@ -Subproject commit 4613afff874c23d17bde580671ff29c7a13123d0 +Subproject commit bc5781caf523eab7e2c0e92478cbbef568a1be43 diff --git a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala index 9d0f5f15de7e..fbae1afcbfbd 100644 --- a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala +++ b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala @@ -66,9 +66,12 @@ trait QuotesAndSplices { typedTypeApply(untpd.TypeApply(untpd.ref(defn.QuotedTypeModule_of.termRef), tree.quoted :: Nil), pt)(using quoteContext).select(nme.apply).appliedTo(qctx) else typedApply(untpd.Apply(untpd.ref(defn.QuotedRuntime_exprQuote.termRef), tree.quoted), pt)(using pushQuotes(qctx)).select(nme.apply).appliedTo(qctx) - tree1.withSpan(tree.span) + makeInlineable(tree1.withSpan(tree.span)) } + private def makeInlineable(tree: Tree)(using Context): Tree = + ctx.compilationUnit.inlineAccessors.makeInlineable(tree) + /** Translate `${ t: Expr[T] }` into expression `t.splice` while tracking the quotation level in the context */ def typedSplice(tree: untpd.Splice, pt: Type)(using Context): Tree = { record("typedSplice") diff --git a/tests/neg-macros/i7068-c.scala b/tests/neg-macros/i7068-c.scala index 7c6714d525c0..b5d416b3240d 100644 --- a/tests/neg-macros/i7068-c.scala +++ b/tests/neg-macros/i7068-c.scala @@ -2,7 +2,7 @@ def species(using quoted.Quotes) = '{ case object Bar // error case class FooT() // error ${ - case object Baz // ok + case object Baz // error ??? } FooT() diff --git a/tests/pos-macros/i12948/Macros_1.scala b/tests/pos-macros/i12948/Macros_1.scala new file mode 100644 index 000000000000..a18d9daec2fe --- /dev/null +++ b/tests/pos-macros/i12948/Macros_1.scala @@ -0,0 +1,9 @@ +package mylib +import scala.quoted.* + +object Main: + protected def foo: Unit = {} + inline def fooCaller: Unit = foo + inline def fooCallerM: Unit = ${ fooMacro } + def fooMacro(using Quotes): Expr[Unit] = + '{ foo } diff --git a/tests/pos-macros/i12948/Test_2.scala b/tests/pos-macros/i12948/Test_2.scala new file mode 100644 index 000000000000..386f1b3bd8f5 --- /dev/null +++ b/tests/pos-macros/i12948/Test_2.scala @@ -0,0 +1,5 @@ +import mylib.Main + +object Test: + Main.fooCaller + Main.fooCallerM diff --git a/tests/pos-macros/i8208/Macros_1.scala b/tests/pos-macros/i8208/Macros_1.scala new file mode 100644 index 000000000000..ce21fadc947a --- /dev/null +++ b/tests/pos-macros/i8208/Macros_1.scala @@ -0,0 +1,22 @@ +package playground + +import scala.quoted._ + +object X { + + inline def power(n: Int, x: Double): Double = + ${ powerImpl('n, 'x) } + + private def powerImpl(nExpr: Expr[Int], xExpr: Expr[Double])(using Quotes): Expr[Double] = + nExpr match { + case Expr(n1) => '{ 42.0 } + case _ => '{ dynamicPower($nExpr, $xExpr) } + } + + private def dynamicPower(n: Int, x: Double): Double = { + println(s"dynamic: $n^$x") + if (n == 0) 1.0 + else if (n % 2 == 0) dynamicPower(n / 2, x * x) + else x * dynamicPower(n - 1, x) + } +} diff --git a/tests/pos-macros/i8208/Test_2.scala b/tests/pos-macros/i8208/Test_2.scala new file mode 100644 index 000000000000..c5e239e50970 --- /dev/null +++ b/tests/pos-macros/i8208/Test_2.scala @@ -0,0 +1,2 @@ +import playground.X +def test(x: Int) = X.power(x, 2)