From 93a804669ae26ed789fbc964294a6fbd79ef8e96 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 15 Nov 2022 10:35:42 +0100 Subject: [PATCH] Remove contents of inline methods Remove contents of inline methods when pickling quotes in case these contain quoted expressions or types. Some artifacts of staging (such as type blocks) are not handled by the transformation phases that follow. Fixes #15985 --- .../tools/dotc/transform/PickleQuotes.scala | 4 +-- tests/pos-macros/i15985.scala | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 tests/pos-macros/i15985.scala diff --git a/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala b/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala index f3ae6a377aab..2452bae09719 100644 --- a/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala @@ -113,12 +113,10 @@ class PickleQuotes extends MacroTransform { case _ => val (contents, tptWithHoles) = makeHoles(tpt) PickleQuotes(quotes, tptWithHoles, contents, tpt.tpe, true) - case tree: DefDef if tree.symbol.is(Macro) => + case tree: DefDef if tree.symbol.is(Macro) || tree.symbol.isInlineMethod => // Shrink size of the tree. The methods have already been inlined. // TODO move to FirstTransform to trigger even without quotes cpy.DefDef(tree)(rhs = defaultValue(tree.rhs.tpe)) - case _: DefDef if tree.symbol.isInlineMethod => - tree case _ => super.transform(tree) } diff --git a/tests/pos-macros/i15985.scala b/tests/pos-macros/i15985.scala new file mode 100644 index 000000000000..cd8a726647f9 --- /dev/null +++ b/tests/pos-macros/i15985.scala @@ -0,0 +1,28 @@ +package anorm.macros +sealed trait Row +sealed trait SqlResult[A] + +import scala.quoted.{ Expr, Quotes, Type } + +private[anorm] object RowParserImpl { + def apply[A](using q:Quotes)(using a: Type[A]): Expr[Row => SqlResult[A]] = { + import q.reflect.* + + inline def f1: Expr[SqlResult[A]] = + Match(???, ???).asExprOf[SqlResult[A]] // (using Type.of[anorm.macros.SqlResult[A]] }) + + inline def f2: Expr[SqlResult[A]] = + Match(???, ???).asExprOf[SqlResult[A]](using Type.of[SqlResult[A]]) + // In Staging phase it becomes + // ..asExprOf[..](using Type.of[{ @SplicedType type a$_$3 = a.Underlying; anorm.macros.SqlResult[a$_$3] }]) + + inline def f3(using Type[SqlResult[A]]): Expr[SqlResult[A]] = + Match(???, ???).asExprOf[SqlResult[A]] + + f1 + f2 + f3 + + ??? + } +}