From d7835d62cf0093e4a8f17f6eabd334e74be6ffcb Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sat, 18 Oct 2014 22:43:57 -0700 Subject: SI-8898 javap -fun under new style lambdas To support both -Ydelambdafy strategies, look for both inline (anonfun) and method (lambda) closure classes. For method (lambda) style, use the anonfun method that is invoked by the accessor. Also, the output of javap must be captured eagerly for filtering for the current target method. If the user asks for a module, e.g., `Foo$`, don't yield results for companion class, but for `Foo`, do yield companion module results. Just because. --- test/files/run/repl-javap-lambdas.scala | 23 +++++++++++++++++++++++ test/files/run/repl-javap-memfun.scala | 4 ++++ 2 files changed, 27 insertions(+) create mode 100644 test/files/run/repl-javap-lambdas.scala (limited to 'test') diff --git a/test/files/run/repl-javap-lambdas.scala b/test/files/run/repl-javap-lambdas.scala new file mode 100644 index 0000000000..15e5bf6877 --- /dev/null +++ b/test/files/run/repl-javap-lambdas.scala @@ -0,0 +1,23 @@ +import scala.tools.partest.JavapTest +import scala.tools.nsc.Settings + +// see repl-javap-memfun.java for the complementary version +object Test extends JavapTest { + override def transformSettings(s: Settings) = { s.Ydelambdafy.value = "method" ; s } + def code = """ + |object Betty { + | List(1,2,3) count (_ % 2 != 0) + | def f = List(1,2,3) filter (_ % 2 != 0) map (_ * 2) + | def g = List(1,2,3) filter (_ % 2 == 0) map (_ * 3) map (_ + 1) + |} + |:javap -fun Betty#g + """.stripMargin + + // three anonfuns of Betty#g + override def yah(res: Seq[String]) = { + import PartialFunction.{ cond => when } + val r = """\s*private static final .* \$anonfun\$\d+\(.*""".r + def filtered = res filter (when(_) { case r(_*) => true }) + 3 == filtered.size + } +} diff --git a/test/files/run/repl-javap-memfun.scala b/test/files/run/repl-javap-memfun.scala index d2b4243c8b..d10ebcb399 100644 --- a/test/files/run/repl-javap-memfun.scala +++ b/test/files/run/repl-javap-memfun.scala @@ -1,6 +1,10 @@ import scala.tools.partest.JavapTest +import scala.tools.nsc.Settings +// see repl-javap-lambdas.scala for the complementary version object Test extends JavapTest { + // asserting the default + override def transformSettings(s: Settings) = { s.Ydelambdafy.value = "inline" ; s } def code = """ |object Betty { | List(1,2,3) count (_ % 2 != 0) -- cgit v1.2.3