Skip to content

Commit c1c2910

Browse files
committed
Fix #8866: Inline calls inserted by macros
1 parent a3b417b commit c1c2910

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
12331233
case res: Apply if res.symbol == defn.InternalQuoted_exprSplice
12341234
&& level == 0
12351235
&& !suppressInline =>
1236-
expandMacro(res.args.head, tree.span)
1236+
val expanded = expandMacro(res.args.head, tree.span)
1237+
typedExpr(expanded) // Inline calls and constant fold code generated by the macro
12371238
case res => res
12381239
}
12391240

tests/pos-macros/i8866/Macro_1.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import scala.quoted._
2+
3+
object OtherMacro {
4+
5+
def impl(using qctx: QuoteContext): Expr[Int] =
6+
'{ 42 }
7+
8+
inline def apply = ${ OtherMacro.impl }
9+
10+
}
11+
12+
object Macro {
13+
14+
def impl(using qctx: QuoteContext): Expr[Int] = {
15+
import qctx.tasty._
16+
17+
let(
18+
Select.unique(
19+
'{ OtherMacro }.unseal,
20+
"apply"
21+
)
22+
)(identity).seal.cast[Int]
23+
}
24+
25+
inline def apply = ${ Macro.impl }
26+
27+
}

tests/pos-macros/i8866/Test_2.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val a = Macro.apply

tests/pos-macros/i8866b/Macro_1.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import scala.quoted._
2+
3+
object Other {
4+
inline def apply = 5
5+
}
6+
7+
object Macro {
8+
9+
def impl(using qctx: QuoteContext): Expr[Int] = {
10+
import qctx.tasty._
11+
12+
let(
13+
Select.unique(
14+
'{ Other }.unseal,
15+
"apply"
16+
)
17+
)(identity).seal.cast[Int]
18+
19+
}
20+
21+
inline def apply = ${ Macro.impl }
22+
23+
}

tests/pos-macros/i8866b/Test_2.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val a = Macro.apply

tests/run-macros/beta-reduce-inline-result.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
compile-time: ((3.+(1): scala.Int): scala.Int)
1+
compile-time: ((4: scala.Int): scala.Int)
22
run-time: 4
33
compile-time: ((1: 1): scala.Int)
44
run-time: 1

0 commit comments

Comments
 (0)