Skip to content

Commit 93a8046

Browse files
committed
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
1 parent 970d119 commit 93a8046

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,10 @@ class PickleQuotes extends MacroTransform {
113113
case _ =>
114114
val (contents, tptWithHoles) = makeHoles(tpt)
115115
PickleQuotes(quotes, tptWithHoles, contents, tpt.tpe, true)
116-
case tree: DefDef if tree.symbol.is(Macro) =>
116+
case tree: DefDef if tree.symbol.is(Macro) || tree.symbol.isInlineMethod =>
117117
// Shrink size of the tree. The methods have already been inlined.
118118
// TODO move to FirstTransform to trigger even without quotes
119119
cpy.DefDef(tree)(rhs = defaultValue(tree.rhs.tpe))
120-
case _: DefDef if tree.symbol.isInlineMethod =>
121-
tree
122120
case _ =>
123121
super.transform(tree)
124122
}

tests/pos-macros/i15985.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package anorm.macros
2+
sealed trait Row
3+
sealed trait SqlResult[A]
4+
5+
import scala.quoted.{ Expr, Quotes, Type }
6+
7+
private[anorm] object RowParserImpl {
8+
def apply[A](using q:Quotes)(using a: Type[A]): Expr[Row => SqlResult[A]] = {
9+
import q.reflect.*
10+
11+
inline def f1: Expr[SqlResult[A]] =
12+
Match(???, ???).asExprOf[SqlResult[A]] // (using Type.of[anorm.macros.SqlResult[A]] })
13+
14+
inline def f2: Expr[SqlResult[A]] =
15+
Match(???, ???).asExprOf[SqlResult[A]](using Type.of[SqlResult[A]])
16+
// In Staging phase it becomes
17+
// ..asExprOf[..](using Type.of[{ @SplicedType type a$_$3 = a.Underlying; anorm.macros.SqlResult[a$_$3] }])
18+
19+
inline def f3(using Type[SqlResult[A]]): Expr[SqlResult[A]] =
20+
Match(???, ???).asExprOf[SqlResult[A]]
21+
22+
f1
23+
f2
24+
f3
25+
26+
???
27+
}
28+
}

0 commit comments

Comments
 (0)