Skip to content

Commit 2b73f9d

Browse files
Merge pull request #5187 from dotty-staging/fix-macro-with-varargs
Fix varargs in macros
2 parents 0309bbf + 251f654 commit 2b73f9d

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ object Splicer {
102102
protected def interpretLiteral(value: Any)(implicit env: Env): Object =
103103
value.asInstanceOf[Object]
104104

105+
protected def interpretVarargs(args: List[Object])(implicit env: Env): Object =
106+
args.toSeq
107+
105108
protected def interpretTastyContext()(implicit env: Env): Object =
106109
new TastyImpl(ctx) {
107110
override def rootPosition: SourcePosition = pos
@@ -240,6 +243,7 @@ object Splicer {
240243
def interpretQuote(tree: tpd.Tree)(implicit env: Env): Boolean = true
241244
def interpretTypeQuote(tree: tpd.Tree)(implicit env: Env): Boolean = true
242245
def interpretLiteral(value: Any)(implicit env: Env): Boolean = true
246+
def interpretVarargs(args: List[Boolean])(implicit env: Env): Boolean = args.forall(identity)
243247
def interpretTastyContext()(implicit env: Env): Boolean = true
244248
def interpretStaticMethodCall(fn: tpd.Tree, args: => List[Boolean])(implicit env: Env): Boolean = args.forall(identity)
245249

@@ -259,6 +263,7 @@ object Splicer {
259263
protected def interpretQuote(tree: Tree)(implicit env: Env): Result
260264
protected def interpretTypeQuote(tree: Tree)(implicit env: Env): Result
261265
protected def interpretLiteral(value: Any)(implicit env: Env): Result
266+
protected def interpretVarargs(args: List[Result])(implicit env: Env): Result
262267
protected def interpretTastyContext()(implicit env: Env): Result
263268
protected def interpretStaticMethodCall(fn: Tree, args: => List[Result])(implicit env: Env): Result
264269
protected def unexpectedTree(tree: Tree)(implicit env: Env): Result
@@ -293,7 +298,10 @@ object Splicer {
293298

294299
case Inlined(EmptyTree, Nil, expansion) => interpretTree(expansion)
295300

296-
case _ => unexpectedTree(tree)
301+
case Typed(SeqLiteral(elems, _), _) => interpretVarargs(elems.map(e => interpretTree(e)))
302+
303+
case _ =>
304+
unexpectedTree(tree)
297305
}
298306

299307
object StaticMethodCall {

compiler/test/dotc/run-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ i4803d
2020
i4803e
2121
i4803f
2222
i4947b
23+
inline-varargs-1
2324
implicitShortcut
2425
lazy-implicit-lists.scala
2526
lazy-implicit-nums.scala

tests/run/inline-varargs-1.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
import scala.quoted._
3+
4+
object Macros {
5+
def sum(nums: Int*): Expr[Int] = nums.sum.toExpr
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
object Test {
3+
4+
def main(args: Array[String]): Unit = {
5+
println(sum(1, 2, 3))
6+
}
7+
8+
inline def sum(inline i: Int, inline j: Int, inline k: Int): Int = ~Macros.sum(i, j, k)
9+
}

0 commit comments

Comments
 (0)