diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-12-30 07:13:14 -0800 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-12-30 07:13:14 -0800 |
commit | 7aa83958e210f3c38e2f072bf149049b6e7462d6 (patch) | |
tree | 49b38616e595b220cff905015812a6b4de26f591 /test/files | |
parent | 6834cc2278ad522e49493b624da95bfa00af1604 (diff) | |
parent | d92effc8a995086c1e0c4482f6163ef17b289ede (diff) | |
download | scala-7aa83958e210f3c38e2f072bf149049b6e7462d6.tar.gz scala-7aa83958e210f3c38e2f072bf149049b6e7462d6.tar.bz2 scala-7aa83958e210f3c38e2f072bf149049b6e7462d6.zip |
Merge pull request #3309 from xeno-by/topic/expand-dynamic
SI-7777 SI-8006 assorted fixes for dynamics
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/neg/t6920.check | 6 | ||||
-rw-r--r-- | test/files/neg/t6920.scala | 10 | ||||
-rw-r--r-- | test/files/neg/t8006.check | 6 | ||||
-rw-r--r-- | test/files/neg/t8006.scala | 8 | ||||
-rw-r--r-- | test/files/run/t7777.check | 7 | ||||
-rw-r--r-- | test/files/run/t7777/Macros_1.scala | 17 | ||||
-rw-r--r-- | test/files/run/t7777/Test_2.scala | 6 |
7 files changed, 60 insertions, 0 deletions
diff --git a/test/files/neg/t6920.check b/test/files/neg/t6920.check new file mode 100644 index 0000000000..ee4eafb83e --- /dev/null +++ b/test/files/neg/t6920.check @@ -0,0 +1,6 @@ +t6920.scala:9: error: too many arguments for method applyDynamicNamed: (values: Seq[(String, Any)])String +error after rewriting to CompilerError.this.test.applyDynamicNamed("crushTheCompiler")(scala.Tuple2("a", 1), scala.Tuple2("b", 2)) +possible cause: maybe a wrong Dynamic method signature? + test.crushTheCompiler(a = 1, b = 2) + ^ +one error found diff --git a/test/files/neg/t6920.scala b/test/files/neg/t6920.scala new file mode 100644 index 0000000000..b79d641698 --- /dev/null +++ b/test/files/neg/t6920.scala @@ -0,0 +1,10 @@ +import scala.language.dynamics + +class DynTest extends Dynamic { + def applyDynamicNamed(name: String)(values: Seq[(String, Any)]) = "test" +} + +class CompilerError { + val test = new DynTest + test.crushTheCompiler(a = 1, b = 2) +}
\ No newline at end of file diff --git a/test/files/neg/t8006.check b/test/files/neg/t8006.check new file mode 100644 index 0000000000..fbac26e3ad --- /dev/null +++ b/test/files/neg/t8006.check @@ -0,0 +1,6 @@ +t8006.scala:3: error: too many arguments for method applyDynamicNamed: (value: (String, Any))String +error after rewriting to X.this.d.applyDynamicNamed("meth")(scala.Tuple2("value1", 10), scala.Tuple2("value2", 100)) +possible cause: maybe a wrong Dynamic method signature? + d.meth(value1 = 10, value2 = 100) // two arguments here, but only one is allowed + ^ +one error found diff --git a/test/files/neg/t8006.scala b/test/files/neg/t8006.scala new file mode 100644 index 0000000000..b2f71c1587 --- /dev/null +++ b/test/files/neg/t8006.scala @@ -0,0 +1,8 @@ +object X { + val d = new D + d.meth(value1 = 10, value2 = 100) // two arguments here, but only one is allowed +} +import language.dynamics +class D extends Dynamic { + def applyDynamicNamed(name: String)(value: (String, Any)) = name +}
\ No newline at end of file diff --git a/test/files/run/t7777.check b/test/files/run/t7777.check new file mode 100644 index 0000000000..162ff2d2a2 --- /dev/null +++ b/test/files/run/t7777.check @@ -0,0 +1,7 @@ +foo(1, 2) +bar(4, 5) +foo(3) +bar(7) +apply(6) +apply(9) +foo(8) diff --git a/test/files/run/t7777/Macros_1.scala b/test/files/run/t7777/Macros_1.scala new file mode 100644 index 0000000000..459ab3edbb --- /dev/null +++ b/test/files/run/t7777/Macros_1.scala @@ -0,0 +1,17 @@ +import scala.language.experimental.macros +import scala.language.dynamics +import scala.reflect.macros.WhiteboxContext + +class DynMacro extends Dynamic { + def applyDynamic(s: String)(xs: Any*): DynMacro = + macro DynMacro.applyDynamicMacro +} + +object DynMacro extends DynMacro { + def applyDynamicMacro(c: WhiteboxContext)(s: c.Expr[String])(xs: c.Expr[Any]*): c.Expr[DynMacro] = { + import c.universe._ + val Literal(Constant(n: String)) = s.tree + val args = xs.map(_.tree.toString).mkString("(", ", ", ")") + c.Expr(q"println(${ n + args }); ${c.prefix.tree}") + } +}
\ No newline at end of file diff --git a/test/files/run/t7777/Test_2.scala b/test/files/run/t7777/Test_2.scala new file mode 100644 index 0000000000..1fe8b63bab --- /dev/null +++ b/test/files/run/t7777/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + DynMacro.foo(1, 2) // prints "foo(1, 2)" + DynMacro.foo(3).bar(4, 5) // prints "bar(4, 5)", then "foo(3)" + DynMacro(6).bar(7) // prints "bar(7)", then "apply(6)" + DynMacro.foo(8)(9) // Fails! +}
\ No newline at end of file |