diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-02-17 17:10:49 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-02-17 22:57:12 +0100 |
commit | e9926a5207aadcfe3831b51b1cd6164757278013 (patch) | |
tree | d388f1445054b6007af493ad6d263f9d585299ff /test/files | |
parent | 91148376049a152edec12348ff9b7e9e93e6ebe1 (diff) | |
download | scala-e9926a5207aadcfe3831b51b1cd6164757278013.tar.gz scala-e9926a5207aadcfe3831b51b1cd6164757278013.tar.bz2 scala-e9926a5207aadcfe3831b51b1cd6164757278013.zip |
Fixes miscellaneous macro bugs
Diffstat (limited to 'test/files')
26 files changed, 147 insertions, 0 deletions
diff --git a/test/files/neg/macro-argtype-mismatch.check b/test/files/neg/macro-argtype-mismatch.check new file mode 100644 index 0000000000..dd867be804 --- /dev/null +++ b/test/files/neg/macro-argtype-mismatch.check @@ -0,0 +1,6 @@ +Test_2.scala:3: error: type mismatch;
+ found : String("2")
+ required: Int
+ foo("2")
+ ^
+one error found
diff --git a/test/files/neg/macro-argtype-mismatch.flags b/test/files/neg/macro-argtype-mismatch.flags new file mode 100644 index 0000000000..7fea2ff901 --- /dev/null +++ b/test/files/neg/macro-argtype-mismatch.flags @@ -0,0 +1 @@ +-Xmacros
\ No newline at end of file diff --git a/test/files/neg/macro-argtype-mismatch/Macros_1.scala b/test/files/neg/macro-argtype-mismatch/Macros_1.scala new file mode 100644 index 0000000000..4b5f98ba37 --- /dev/null +++ b/test/files/neg/macro-argtype-mismatch/Macros_1.scala @@ -0,0 +1,3 @@ +object Macros { + def macro foo(x: Int) = x +}
\ No newline at end of file diff --git a/test/files/neg/macro-argtype-mismatch/Test_2.scala b/test/files/neg/macro-argtype-mismatch/Test_2.scala new file mode 100644 index 0000000000..18feb69425 --- /dev/null +++ b/test/files/neg/macro-argtype-mismatch/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + import Macros._ + foo("2") +}
\ No newline at end of file diff --git a/test/files/neg/macro-noexpand.check b/test/files/neg/macro-noexpand.check new file mode 100644 index 0000000000..c15d54bb32 --- /dev/null +++ b/test/files/neg/macro-noexpand.check @@ -0,0 +1,4 @@ +Test_2.scala:3: error: not found: value x
+ foo(x)
+ ^
+one error found
diff --git a/test/files/neg/macro-noexpand.flags b/test/files/neg/macro-noexpand.flags new file mode 100644 index 0000000000..7fea2ff901 --- /dev/null +++ b/test/files/neg/macro-noexpand.flags @@ -0,0 +1 @@ +-Xmacros
\ No newline at end of file diff --git a/test/files/neg/macro-noexpand/Macros_1.scala b/test/files/neg/macro-noexpand/Macros_1.scala new file mode 100644 index 0000000000..7a6aadf6a1 --- /dev/null +++ b/test/files/neg/macro-noexpand/Macros_1.scala @@ -0,0 +1,3 @@ +object Macros { + def macro foo(x: Any) = ??? +}
\ No newline at end of file diff --git a/test/files/neg/macro-noexpand/Test_2.scala b/test/files/neg/macro-noexpand/Test_2.scala new file mode 100644 index 0000000000..0bed592883 --- /dev/null +++ b/test/files/neg/macro-noexpand/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + import Macros._ + foo(x) +}
\ No newline at end of file diff --git a/test/files/neg/macro-noncompilertree.check b/test/files/neg/macro-noncompilertree.check new file mode 100644 index 0000000000..616765a39e --- /dev/null +++ b/test/files/neg/macro-noncompilertree.check @@ -0,0 +1,6 @@ +Macros_1.scala:2: error: type mismatch;
+ found : reflect.mirror.Literal
+ required: _context.Tree
+ def macro foo = scala.reflect.mirror.Literal(scala.reflect.mirror.Constant(2))
+ ^
+one error found
diff --git a/test/files/neg/macro-noncompilertree.flags b/test/files/neg/macro-noncompilertree.flags new file mode 100644 index 0000000000..7fea2ff901 --- /dev/null +++ b/test/files/neg/macro-noncompilertree.flags @@ -0,0 +1 @@ +-Xmacros
\ No newline at end of file diff --git a/test/files/neg/macro-noncompilertree/Macros_1.scala b/test/files/neg/macro-noncompilertree/Macros_1.scala new file mode 100644 index 0000000000..eb1253e5e9 --- /dev/null +++ b/test/files/neg/macro-noncompilertree/Macros_1.scala @@ -0,0 +1,3 @@ +object Macros { + def macro foo = scala.reflect.mirror.Literal(scala.reflect.mirror.Constant(2)) +}
\ No newline at end of file diff --git a/test/files/neg/macro-nontree.check b/test/files/neg/macro-nontree.check new file mode 100644 index 0000000000..a1c7139580 --- /dev/null +++ b/test/files/neg/macro-nontree.check @@ -0,0 +1,6 @@ +Macros_1.scala:2: error: type mismatch;
+ found : Int(2)
+ required: _context.Tree
+ def macro foo = 2
+ ^
+one error found
diff --git a/test/files/neg/macro-nontree.flags b/test/files/neg/macro-nontree.flags new file mode 100644 index 0000000000..7fea2ff901 --- /dev/null +++ b/test/files/neg/macro-nontree.flags @@ -0,0 +1 @@ +-Xmacros
\ No newline at end of file diff --git a/test/files/neg/macro-nontree/Macros_1.scala b/test/files/neg/macro-nontree/Macros_1.scala new file mode 100644 index 0000000000..2433974a85 --- /dev/null +++ b/test/files/neg/macro-nontree/Macros_1.scala @@ -0,0 +1,3 @@ +object Macros { + def macro foo = 2 +}
\ No newline at end of file diff --git a/test/files/run/macro-basic.check b/test/files/run/macro-basic.check new file mode 100644 index 0000000000..d434014897 --- /dev/null +++ b/test/files/run/macro-basic.check @@ -0,0 +1 @@ +10
diff --git a/test/files/run/macro-basic.flags b/test/files/run/macro-basic.flags new file mode 100644 index 0000000000..06a7b31f11 --- /dev/null +++ b/test/files/run/macro-basic.flags @@ -0,0 +1 @@ +-Xmacros diff --git a/test/files/run/macro-basic/Macros_1.scala b/test/files/run/macro-basic/Macros_1.scala new file mode 100644 index 0000000000..c2ea183abe --- /dev/null +++ b/test/files/run/macro-basic/Macros_1.scala @@ -0,0 +1,10 @@ +object Macros { + object Shmacros { + def macro foo(x: Int): Int = x + } + def macro bar(x: Int): Int = x +} + +class Macros { + def macro quux(x: Int): Int = x +}
\ No newline at end of file diff --git a/test/files/run/macro-basic/Test_2.scala b/test/files/run/macro-basic/Test_2.scala new file mode 100644 index 0000000000..e9a10e20c9 --- /dev/null +++ b/test/files/run/macro-basic/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + import Macros.Shmacros._ + println(foo(2) + Macros.bar(2) * new Macros().quux(4)) +}
\ No newline at end of file diff --git a/test/files/run/macro-repl-basic.check b/test/files/run/macro-repl-basic.check new file mode 100644 index 0000000000..f8f0d3ad29 --- /dev/null +++ b/test/files/run/macro-repl-basic.check @@ -0,0 +1,25 @@ +Type in expressions to have them evaluated.
+Type :help for more information.
+
+scala>
+
+scala> object Macros {
+ object Shmacros {
+ def macro foo(x: Int): Int = x
+ }
+ def macro bar(x: Int): Int = x
+}; class Macros {
+ def macro quux(x: Int): Int = x
+}
+defined module Macros
+defined class Macros
+
+scala>
+
+scala> import Macros.Shmacros._
+import Macros.Shmacros._
+
+scala> println(foo(2) + Macros.bar(2) * new Macros().quux(4))
+10
+
+scala>
diff --git a/test/files/run/macro-repl-basic.scala b/test/files/run/macro-repl-basic.scala new file mode 100644 index 0000000000..9b1a53343b --- /dev/null +++ b/test/files/run/macro-repl-basic.scala @@ -0,0 +1,18 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + override def extraSettings = "-Xmacros" + def code = """ + |object Macros { + | object Shmacros { + | def macro foo(x: Int): Int = x + | } + | def macro bar(x: Int): Int = x + |}; class Macros { + | def macro quux(x: Int): Int = x + |} + | + |import Macros.Shmacros._ + |println(foo(2) + Macros.bar(2) * new Macros().quux(4)) + |""".stripMargin +}
\ No newline at end of file diff --git a/test/files/run/macro-repl-dontexpand.check b/test/files/run/macro-repl-dontexpand.check new file mode 100644 index 0000000000..d2bb89b6f7 --- /dev/null +++ b/test/files/run/macro-repl-dontexpand.check @@ -0,0 +1,9 @@ +Type in expressions to have them evaluated.
+Type :help for more information.
+
+scala>
+
+scala> def macro foo = ???
+foo: Any
+
+scala>
diff --git a/test/files/run/macro-repl-dontexpand.scala b/test/files/run/macro-repl-dontexpand.scala new file mode 100644 index 0000000000..254bce894c --- /dev/null +++ b/test/files/run/macro-repl-dontexpand.scala @@ -0,0 +1,8 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + override def extraSettings = "-Xmacros" + def code = """ + |def macro foo = ??? + |""".stripMargin +}
\ No newline at end of file diff --git a/test/files/run/macro-rettype-mismatch.check b/test/files/run/macro-rettype-mismatch.check new file mode 100644 index 0000000000..f6e4bc09fd --- /dev/null +++ b/test/files/run/macro-rettype-mismatch.check @@ -0,0 +1,5 @@ +error: type mismatch; + found : Int(2) + required: String +
+java.lang.Error: reflective compilation has failed
diff --git a/test/files/run/macro-rettype-mismatch.flags b/test/files/run/macro-rettype-mismatch.flags new file mode 100644 index 0000000000..7fea2ff901 --- /dev/null +++ b/test/files/run/macro-rettype-mismatch.flags @@ -0,0 +1 @@ +-Xmacros
\ No newline at end of file diff --git a/test/files/run/macro-rettype-mismatch/Macros_1.scala b/test/files/run/macro-rettype-mismatch/Macros_1.scala new file mode 100644 index 0000000000..64e5b93468 --- /dev/null +++ b/test/files/run/macro-rettype-mismatch/Macros_1.scala @@ -0,0 +1,3 @@ +object Macros { + def macro foo(x: Int): String = x +}
\ No newline at end of file diff --git a/test/files/run/macro-rettype-mismatch/Test_2.scala b/test/files/run/macro-rettype-mismatch/Test_2.scala new file mode 100644 index 0000000000..39a7c7ad1a --- /dev/null +++ b/test/files/run/macro-rettype-mismatch/Test_2.scala @@ -0,0 +1,16 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + import scala.reflect.mirror._ + val tree = Apply(Select(Ident("Macros"), newTermName("foo")), List(Literal(Constant(2)))) + + val stderr = new java.io.ByteArrayOutputStream() + Console.setErr(new java.io.PrintStream(stderr)) + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + try { toolbox.runExpr(tree) } + catch { case ex: Throwable => println(stderr); println(ex) } +} |