diff options
author | James Iry <james.iry@typesafe.com> | 2013-08-28 20:41:12 -0700 |
---|---|---|
committer | James Iry <james.iry@typesafe.com> | 2013-11-06 12:28:19 -0800 |
commit | 5d29697365245707af1a037678a7b48b0fef341c (patch) | |
tree | e21103cae9992c26774c61cd1e8ebc8b1381435f /test/files/run | |
parent | 510b8cecc4951ff8092cfa931c2dc3717e21dded (diff) | |
download | scala-5d29697365245707af1a037678a7b48b0fef341c.tar.gz scala-5d29697365245707af1a037678a7b48b0fef341c.tar.bz2 scala-5d29697365245707af1a037678a7b48b0fef341c.zip |
Flesh out the Delambdafy phase.
This commit puts a real body on the Delambdafy phase.
From a lambda, Delambdafy will create
1) a static forwarder at the top level of the class that contained
the lambda
2) a new top level class that
a) has fields and a constructor taking the captured environment
(including possbily the "this" reference)
b) an apply method that calls the static forwarder
c) if needed a bridge method for the apply method
3) an instantiation of the newly created class which replaces the
lambda
Trees.scala is modified to add two more convenient factories
for templates and classdefs.
A few basic tests are included to verify that it works as expected.
Further commits will have additional tests.
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/delambdafy-nested-by-name.check | 2 | ||||
-rw-r--r-- | test/files/run/delambdafy-nested-by-name.scala | 11 | ||||
-rw-r--r-- | test/files/run/delambdafy-two-lambdas.check | 2 | ||||
-rw-r--r-- | test/files/run/delambdafy-two-lambdas.scala | 12 |
4 files changed, 27 insertions, 0 deletions
diff --git a/test/files/run/delambdafy-nested-by-name.check b/test/files/run/delambdafy-nested-by-name.check new file mode 100644 index 0000000000..94954abda4 --- /dev/null +++ b/test/files/run/delambdafy-nested-by-name.check @@ -0,0 +1,2 @@ +hello +world diff --git a/test/files/run/delambdafy-nested-by-name.scala b/test/files/run/delambdafy-nested-by-name.scala new file mode 100644 index 0000000000..4498b3308d --- /dev/null +++ b/test/files/run/delambdafy-nested-by-name.scala @@ -0,0 +1,11 @@ +// during development of delayed delambdafication I created a bug where calling a by-name method with a by-name argument that +// itself contained a by-name argument would cause a class cast exception. That bug wasn't found in the existing test suite +// so this test covers that case +object Test { + def meth1(arg1: => String) = arg1 + def meth2(arg2: => String) = meth1({println("hello"); arg2}) + + def main(args: Array[String]) { + println(meth2("world")) + } +}
\ No newline at end of file diff --git a/test/files/run/delambdafy-two-lambdas.check b/test/files/run/delambdafy-two-lambdas.check new file mode 100644 index 0000000000..ed9ea404dd --- /dev/null +++ b/test/files/run/delambdafy-two-lambdas.check @@ -0,0 +1,2 @@ +13 +24 diff --git a/test/files/run/delambdafy-two-lambdas.scala b/test/files/run/delambdafy-two-lambdas.scala new file mode 100644 index 0000000000..decede74a4 --- /dev/null +++ b/test/files/run/delambdafy-two-lambdas.scala @@ -0,0 +1,12 @@ +/* + * Tests if two lambdas defined in the same class do not lead to + * name clashes. + */ +object Test { + def takeLambda(f: Int => Int ): Int = f(12) + + def main(args: Array[String]): Unit = { + println(takeLambda(x => x+1)) + println(takeLambda(x => x*2)) + } +} |