diff options
author | Josh Suereth <Joshua.Suereth@gmail.com> | 2012-09-03 17:35:17 -0700 |
---|---|---|
committer | Josh Suereth <Joshua.Suereth@gmail.com> | 2012-09-03 17:35:17 -0700 |
commit | 291754799ae498d2b64ac4ac612e4d376a539f05 (patch) | |
tree | 00f90500df39c1434e7e9ea8c9489b6b4bfc3617 /test | |
parent | 5415272018114bb2e15036c5d6f9ae9c5af625d2 (diff) | |
parent | 24a54107f3e3e72a079ebe7e425671e3307d1237 (diff) | |
download | scala-291754799ae498d2b64ac4ac612e4d376a539f05.tar.gz scala-291754799ae498d2b64ac4ac612e4d376a539f05.tar.bz2 scala-291754799ae498d2b64ac4ac612e4d376a539f05.zip |
Merge pull request #1242 from paulp/topic/dynamic-anyval
Made Dynamic extend Any.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/dynamic-anyval.check | 4 | ||||
-rw-r--r-- | test/files/run/dynamic-anyval.scala | 22 |
2 files changed, 26 insertions, 0 deletions
diff --git a/test/files/run/dynamic-anyval.check b/test/files/run/dynamic-anyval.check new file mode 100644 index 0000000000..dee7bef8e8 --- /dev/null +++ b/test/files/run/dynamic-anyval.check @@ -0,0 +1,4 @@ +().dingo(bippy, 5) +List(1, 2, 3).dingo(bippy, 5) +().dingo(bippy, 5) +List(1, 2, 3).dingo(bippy, 5) diff --git a/test/files/run/dynamic-anyval.scala b/test/files/run/dynamic-anyval.scala new file mode 100644 index 0000000000..605503d377 --- /dev/null +++ b/test/files/run/dynamic-anyval.scala @@ -0,0 +1,22 @@ +import scala.language.dynamics + +object Test { + implicit class DynamicValue[T](val value: T) extends AnyVal with Dynamic { + def applyDynamic(name: String)(args: Any*) = println(s"""$this.$name(${args mkString ", "})""") + override def toString = "" + value + } + implicit class DynamicValue2[T](val value: T) extends Dynamic { + def applyDynamic(name: String)(args: Any*) = println(s"""$this.$name(${args mkString ", "})""") + override def toString = "" + value + } + + def f[T](x: DynamicValue[T]) = x.dingo("bippy", 5) + def g[T](x: DynamicValue2[T]) = x.dingo("bippy", 5) + + def main(args: Array[String]): Unit = { + f(()) + f(List(1, 2, 3)) + g(()) + g(List(1, 2, 3)) + } +} |