Skip to content

Fix varargs in macros #5187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ object Splicer {
protected def interpretLiteral(value: Any)(implicit env: Env): Object =
value.asInstanceOf[Object]

protected def interpretVarargs(args: List[Object])(implicit env: Env): Object =
args.toSeq

protected def interpretTastyContext()(implicit env: Env): Object =
new TastyImpl(ctx) {
override def rootPosition: SourcePosition = pos
Expand Down Expand Up @@ -240,6 +243,7 @@ object Splicer {
def interpretQuote(tree: tpd.Tree)(implicit env: Env): Boolean = true
def interpretTypeQuote(tree: tpd.Tree)(implicit env: Env): Boolean = true
def interpretLiteral(value: Any)(implicit env: Env): Boolean = true
def interpretVarargs(args: List[Boolean])(implicit env: Env): Boolean = args.forall(identity)
def interpretTastyContext()(implicit env: Env): Boolean = true
def interpretStaticMethodCall(fn: tpd.Tree, args: => List[Boolean])(implicit env: Env): Boolean = args.forall(identity)

Expand All @@ -259,6 +263,7 @@ object Splicer {
protected def interpretQuote(tree: Tree)(implicit env: Env): Result
protected def interpretTypeQuote(tree: Tree)(implicit env: Env): Result
protected def interpretLiteral(value: Any)(implicit env: Env): Result
protected def interpretVarargs(args: List[Result])(implicit env: Env): Result
protected def interpretTastyContext()(implicit env: Env): Result
protected def interpretStaticMethodCall(fn: Tree, args: => List[Result])(implicit env: Env): Result
protected def unexpectedTree(tree: Tree)(implicit env: Env): Result
Expand Down Expand Up @@ -293,7 +298,10 @@ object Splicer {

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

case _ => unexpectedTree(tree)
case Typed(SeqLiteral(elems, _), _) => interpretVarargs(elems.map(e => interpretTree(e)))

case _ =>
unexpectedTree(tree)
}

object StaticMethodCall {
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/run-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ i4803d
i4803e
i4803f
i4947b
inline-varargs-1
implicitShortcut
lazy-implicit-lists.scala
lazy-implicit-nums.scala
Expand Down
1 change: 1 addition & 0 deletions tests/run/inline-varargs-1.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6
6 changes: 6 additions & 0 deletions tests/run/inline-varargs-1/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

import scala.quoted._

object Macros {
def sum(nums: Int*): Expr[Int] = nums.sum.toExpr
}
9 changes: 9 additions & 0 deletions tests/run/inline-varargs-1/Main_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

object Test {

def main(args: Array[String]): Unit = {
println(sum(1, 2, 3))
}

inline def sum(inline i: Int, inline j: Int, inline k: Int): Int = ~Macros.sum(i, j, k)
}