summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-01-14 17:29:42 +0100
committerEugene Burmako <xeno.by@gmail.com>2013-05-28 08:23:44 +0200
commite1d9805c91dbe74317e2f4f22ad59056d64d12b3 (patch)
treecf8c3f135adfdcbfa090c3c408b7bce407c3cdeb /test
parent43249001a566c46d6bb3b515045ab477b42a0c77 (diff)
downloadscala-e1d9805c91dbe74317e2f4f22ad59056d64d12b3.tar.gz
scala-e1d9805c91dbe74317e2f4f22ad59056d64d12b3.tar.bz2
scala-e1d9805c91dbe74317e2f4f22ad59056d64d12b3.zip
macro engine refactoring
Macro impl bindings now store more information in signatures. Previously it was a flattened List[Int] corresponding to flattened paramss, now it's List[List[Int]] to preserve the lengths of parameter lists. Also now we distinguish between c.Expr parameters and others. Previously actual and reference macro signatures were represented as tuples of vparamss, rets, and sometimes tparams. Now they are all abstracted behind MacroImplSig. Finally this patch provides better error messages in cases of argsc <-> paramsc and argc <-> paramc mismatches.
Diffstat (limited to 'test')
-rw-r--r--test/files/neg/macro-qmarkqmarkqmark.check2
-rw-r--r--test/files/neg/t7157.check73
-rw-r--r--test/files/neg/t7157/Impls_Macros_1.scala32
-rw-r--r--test/files/neg/t7157/Test_2.scala63
-rw-r--r--test/files/run/macro-invalidusage-partialapplication-with-tparams.check2
-rw-r--r--test/files/run/macro-invalidusage-partialapplication.check2
-rw-r--r--test/files/run/reify-repl-fail-gracefully.check2
-rw-r--r--test/files/run/t7157.check1
-rw-r--r--test/files/run/t7157/Impls_Macros_1.scala15
-rw-r--r--test/files/run/t7157/Test_2.scala5
10 files changed, 193 insertions, 4 deletions
diff --git a/test/files/neg/macro-qmarkqmarkqmark.check b/test/files/neg/macro-qmarkqmarkqmark.check
index afd49e7d90..bc3e25edaf 100644
--- a/test/files/neg/macro-qmarkqmarkqmark.check
+++ b/test/files/neg/macro-qmarkqmarkqmark.check
@@ -1,7 +1,7 @@
macro-qmarkqmarkqmark.scala:5: error: macro implementation is missing
foo1
^
-macro-qmarkqmarkqmark.scala:8: error: macros cannot be partially applied
+macro-qmarkqmarkqmark.scala:8: error: too few argument lists for macro invocation
foo2
^
macro-qmarkqmarkqmark.scala:9: error: macro implementation is missing
diff --git a/test/files/neg/t7157.check b/test/files/neg/t7157.check
new file mode 100644
index 0000000000..c6a7af9a23
--- /dev/null
+++ b/test/files/neg/t7157.check
@@ -0,0 +1,73 @@
+Test_2.scala:5: error: too many arguments for macro method m1_0_0: ()Unit
+ m1_0_0(1)
+ ^
+Test_2.scala:6: error: too many arguments for macro method m1_0_0: ()Unit
+ m1_0_0(1, 2)
+ ^
+Test_2.scala:7: error: too many arguments for macro method m1_0_0: ()Unit
+ m1_0_0(1, 2, 3)
+ ^
+Test_2.scala:9: error: macro applications do not support named and/or default arguments
+ m1_1_1()
+ ^
+Test_2.scala:11: error: too many arguments for macro method m1_1_1: (x: Int)Unit
+ m1_1_1(1, 2)
+ ^
+Test_2.scala:12: error: too many arguments for macro method m1_1_1: (x: Int)Unit
+ m1_1_1(1, 2, 3)
+ ^
+Test_2.scala:14: error: macro applications do not support named and/or default arguments
+ m1_2_2()
+ ^
+Test_2.scala:15: error: macro applications do not support named and/or default arguments
+ m1_2_2(1)
+ ^
+Test_2.scala:17: error: too many arguments for macro method m1_2_2: (x: Int, y: Int)Unit
+ m1_2_2(1, 2, 3)
+ ^
+Test_2.scala:24: error: macro applications do not support named and/or default arguments
+ m1_1_inf()
+ ^
+Test_2.scala:29: error: macro applications do not support named and/or default arguments
+ m1_2_inf()
+ ^
+Test_2.scala:30: error: macro applications do not support named and/or default arguments
+ m1_2_inf(1)
+ ^
+Test_2.scala:35: error: too many arguments for macro method m2_0_0: ()Unit
+ m2_0_0()(1)
+ ^
+Test_2.scala:36: error: too many arguments for macro method m2_0_0: ()Unit
+ m2_0_0()(1, 2)
+ ^
+Test_2.scala:37: error: too many arguments for macro method m2_0_0: ()Unit
+ m2_0_0()(1, 2, 3)
+ ^
+Test_2.scala:39: error: macro applications do not support named and/or default arguments
+ m2_1_1()()
+ ^
+Test_2.scala:41: error: too many arguments for macro method m2_1_1: (x: Int)Unit
+ m2_1_1()(1, 2)
+ ^
+Test_2.scala:42: error: too many arguments for macro method m2_1_1: (x: Int)Unit
+ m2_1_1()(1, 2, 3)
+ ^
+Test_2.scala:44: error: macro applications do not support named and/or default arguments
+ m2_2_2()()
+ ^
+Test_2.scala:45: error: macro applications do not support named and/or default arguments
+ m2_2_2()(1)
+ ^
+Test_2.scala:47: error: too many arguments for macro method m2_2_2: (x: Int, y: Int)Unit
+ m2_2_2()(1, 2, 3)
+ ^
+Test_2.scala:54: error: macro applications do not support named and/or default arguments
+ m2_1_inf()()
+ ^
+Test_2.scala:59: error: macro applications do not support named and/or default arguments
+ m2_2_inf()()
+ ^
+Test_2.scala:60: error: macro applications do not support named and/or default arguments
+ m2_2_inf()(1)
+ ^
+24 errors found
diff --git a/test/files/neg/t7157/Impls_Macros_1.scala b/test/files/neg/t7157/Impls_Macros_1.scala
new file mode 100644
index 0000000000..09f423fbab
--- /dev/null
+++ b/test/files/neg/t7157/Impls_Macros_1.scala
@@ -0,0 +1,32 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+object Macros {
+ def impl1_0_0(c: Context)() = c.literalUnit
+ def impl1_1_1(c: Context)(x: c.Expr[Int]) = c.literalUnit
+ def impl1_2_2(c: Context)(x: c.Expr[Int], y: c.Expr[Int]) = c.literalUnit
+ def m1_0_0() = macro impl1_0_0
+ def m1_1_1(x: Int) = macro impl1_1_1
+ def m1_2_2(x: Int, y: Int) = macro impl1_2_2
+
+ def impl1_0_inf(c: Context)(x: c.Expr[Int]*) = c.literalUnit
+ def impl1_1_inf(c: Context)(x: c.Expr[Int], y: c.Expr[Int]*) = c.literalUnit
+ def impl1_2_inf(c: Context)(x: c.Expr[Int], y: c.Expr[Int], z: c.Expr[Int]*) = c.literalUnit
+ def m1_0_inf(x: Int*) = macro impl1_0_inf
+ def m1_1_inf(x: Int, y: Int*) = macro impl1_1_inf
+ def m1_2_inf(x: Int, y: Int, z: Int*) = macro impl1_2_inf
+
+ def impl2_0_0(c: Context)()() = c.literalUnit
+ def impl2_1_1(c: Context)()(x: c.Expr[Int]) = c.literalUnit
+ def impl2_2_2(c: Context)()(x: c.Expr[Int], y: c.Expr[Int]) = c.literalUnit
+ def m2_0_0()() = macro impl2_0_0
+ def m2_1_1()(x: Int) = macro impl2_1_1
+ def m2_2_2()(x: Int, y: Int) = macro impl2_2_2
+
+ def impl2_0_inf(c: Context)()(x: c.Expr[Int]*) = c.literalUnit
+ def impl2_1_inf(c: Context)()(x: c.Expr[Int], y: c.Expr[Int]*) = c.literalUnit
+ def impl2_2_inf(c: Context)()(x: c.Expr[Int], y: c.Expr[Int], z: c.Expr[Int]*) = c.literalUnit
+ def m2_0_inf()(x: Int*) = macro impl2_0_inf
+ def m2_1_inf()(x: Int, y: Int*) = macro impl2_1_inf
+ def m2_2_inf()(x: Int, y: Int, z: Int*) = macro impl2_2_inf
+} \ No newline at end of file
diff --git a/test/files/neg/t7157/Test_2.scala b/test/files/neg/t7157/Test_2.scala
new file mode 100644
index 0000000000..45a6026399
--- /dev/null
+++ b/test/files/neg/t7157/Test_2.scala
@@ -0,0 +1,63 @@
+import Macros._
+
+object Test extends App {
+ m1_0_0()
+ m1_0_0(1)
+ m1_0_0(1, 2)
+ m1_0_0(1, 2, 3)
+
+ m1_1_1()
+ m1_1_1(1)
+ m1_1_1(1, 2)
+ m1_1_1(1, 2, 3)
+
+ m1_2_2()
+ m1_2_2(1)
+ m1_2_2(1, 2)
+ m1_2_2(1, 2, 3)
+
+ m1_0_inf()
+ m1_0_inf(1)
+ m1_0_inf(1, 2)
+ m1_0_inf(1, 2, 3)
+
+ m1_1_inf()
+ m1_1_inf(1)
+ m1_1_inf(1, 2)
+ m1_1_inf(1, 2, 3)
+
+ m1_2_inf()
+ m1_2_inf(1)
+ m1_2_inf(1, 2)
+ m1_2_inf(1, 2, 3)
+
+ m2_0_0()()
+ m2_0_0()(1)
+ m2_0_0()(1, 2)
+ m2_0_0()(1, 2, 3)
+
+ m2_1_1()()
+ m2_1_1()(1)
+ m2_1_1()(1, 2)
+ m2_1_1()(1, 2, 3)
+
+ m2_2_2()()
+ m2_2_2()(1)
+ m2_2_2()(1, 2)
+ m2_2_2()(1, 2, 3)
+
+ m2_0_inf()()
+ m2_0_inf()(1)
+ m2_0_inf()(1, 2)
+ m2_0_inf()(1, 2, 3)
+
+ m2_1_inf()()
+ m2_1_inf()(1)
+ m2_1_inf()(1, 2)
+ m2_1_inf()(1, 2, 3)
+
+ m2_2_inf()()
+ m2_2_inf()(1)
+ m2_2_inf()(1, 2)
+ m2_2_inf()(1, 2, 3)
+} \ No newline at end of file
diff --git a/test/files/run/macro-invalidusage-partialapplication-with-tparams.check b/test/files/run/macro-invalidusage-partialapplication-with-tparams.check
index f1d5e925fa..326f3e08ca 100644
--- a/test/files/run/macro-invalidusage-partialapplication-with-tparams.check
+++ b/test/files/run/macro-invalidusage-partialapplication-with-tparams.check
@@ -1,3 +1,3 @@
reflective compilation has failed:
-macros cannot be partially applied
+too few argument lists for macro invocation
diff --git a/test/files/run/macro-invalidusage-partialapplication.check b/test/files/run/macro-invalidusage-partialapplication.check
index f1d5e925fa..326f3e08ca 100644
--- a/test/files/run/macro-invalidusage-partialapplication.check
+++ b/test/files/run/macro-invalidusage-partialapplication.check
@@ -1,3 +1,3 @@
reflective compilation has failed:
-macros cannot be partially applied
+too few argument lists for macro invocation
diff --git a/test/files/run/reify-repl-fail-gracefully.check b/test/files/run/reify-repl-fail-gracefully.check
index 1b0f3f2162..18cfd5a7ef 100644
--- a/test/files/run/reify-repl-fail-gracefully.check
+++ b/test/files/run/reify-repl-fail-gracefully.check
@@ -12,7 +12,7 @@ import scala.reflect.runtime.universe._
scala>
scala> reify
-<console>:12: error: macros cannot be partially applied
+<console>:12: error: too few argument lists for macro invocation
reify
^
diff --git a/test/files/run/t7157.check b/test/files/run/t7157.check
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/test/files/run/t7157.check
@@ -0,0 +1 @@
+1
diff --git a/test/files/run/t7157/Impls_Macros_1.scala b/test/files/run/t7157/Impls_Macros_1.scala
new file mode 100644
index 0000000000..ad3d96eb85
--- /dev/null
+++ b/test/files/run/t7157/Impls_Macros_1.scala
@@ -0,0 +1,15 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+object Macros {
+ object AImpl {
+ def a(ctx: Context)(args: ctx.Expr[Any]*): ctx.Expr[Unit] = {
+ import ctx.universe._
+ ctx.Expr[Unit](Apply(Ident(TermName("println")), List(Literal(Constant(1)))))
+ }
+ }
+
+ implicit class A(context: StringContext) {
+ def a(args: Any*): Unit = macro AImpl.a
+ }
+} \ No newline at end of file
diff --git a/test/files/run/t7157/Test_2.scala b/test/files/run/t7157/Test_2.scala
new file mode 100644
index 0000000000..cceb5ca177
--- /dev/null
+++ b/test/files/run/t7157/Test_2.scala
@@ -0,0 +1,5 @@
+import Macros._
+
+object Test extends App {
+ a""
+} \ No newline at end of file