summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/files/pos/t8359-closelim-crash.flags1
-rw-r--r--test/files/pos/t8359-closelim-crash.scala23
-rw-r--r--test/pending/run/delambdafy-lambdametafactory.scala50
3 files changed, 74 insertions, 0 deletions
diff --git a/test/files/pos/t8359-closelim-crash.flags b/test/files/pos/t8359-closelim-crash.flags
new file mode 100644
index 0000000000..49d036a887
--- /dev/null
+++ b/test/files/pos/t8359-closelim-crash.flags
@@ -0,0 +1 @@
+-optimize
diff --git a/test/files/pos/t8359-closelim-crash.scala b/test/files/pos/t8359-closelim-crash.scala
new file mode 100644
index 0000000000..1413694d10
--- /dev/null
+++ b/test/files/pos/t8359-closelim-crash.scala
@@ -0,0 +1,23 @@
+package test
+
+// This is a minimization of code that crashed the compiler during bootstrapping
+// in the first iteration of https://github.com/scala/scala/pull/4373, the PR
+// that adjusted the order of free and declared params in LambdaLift.
+
+// Was:
+// java.lang.AssertionError: assertion failed:
+// Record Record(<$anon: Function1>,Map(value a$1 -> Deref(LocalVar(value b)))) does not contain a field value b$1
+// at scala.tools.nsc.Global.assert(Global.scala:262)
+// at scala.tools.nsc.backend.icode.analysis.CopyPropagation$copyLattice$State.getFieldNonRecordValue(CopyPropagation.scala:113)
+// at scala.tools.nsc.backend.icode.analysis.CopyPropagation$copyLattice$State.getFieldNonRecordValue(CopyPropagation.scala:122)
+// at scala.tools.nsc.backend.opt.ClosureElimination$ClosureElim$$anonfun$analyzeMethod$1$$anonfun$apply$2.replaceFieldAccess$1(ClosureElimination.scala:124)
+class Typer {
+ def bar(a: Boolean, b: Boolean): Unit = {
+ @inline
+ def baz(): Unit = {
+ ((_: Any) => (Typer.this, a, b)).apply("")
+ }
+ ((_: Any) => baz()).apply("")
+ }
+}
+
diff --git a/test/pending/run/delambdafy-lambdametafactory.scala b/test/pending/run/delambdafy-lambdametafactory.scala
new file mode 100644
index 0000000000..daea8a39fe
--- /dev/null
+++ b/test/pending/run/delambdafy-lambdametafactory.scala
@@ -0,0 +1,50 @@
+//
+// Tests that the static accessor method for lambda bodies
+// (generated under -Ydelambdafy:method) are compatible with
+// Java 8's LambdaMetafactory.
+//
+import java.lang.invoke._
+
+class C {
+ def test1: Unit = {
+ (x: String) => x.reverse
+ }
+ def test2: Unit = {
+ val capture1 = "capture1"
+ (x: String) => capture1 + " " + x.reverse
+ }
+ def test3: Unit = {
+ (x: String) => C.this + " " + x.reverse
+ }
+}
+trait T {
+ def test4: Unit = {
+ (x: String) => x.reverse
+ }
+}
+
+// A functional interface. Function1 contains abstract methods that are filled in by mixin
+trait Function1ish[A, B] {
+ def apply(a: A): B
+}
+
+object Test {
+ def lambdaFactory[A, B](hostClass: Class[_], instantiatedParam: Class[A], instantiatedRet: Class[B], accessorName: String,
+ capturedParams: Array[(Class[_], AnyRef)] = Array()) = {
+ val caller = MethodHandles.lookup
+ val methodType = MethodType.methodType(classOf[AnyRef], Array[Class[_]](classOf[AnyRef]))
+ val instantiatedMethodType = MethodType.methodType(instantiatedRet, Array[Class[_]](instantiatedParam))
+ val (capturedParamTypes, captured) = capturedParams.unzip
+ val targetMethodType = MethodType.methodType(instantiatedRet, capturedParamTypes :+ instantiatedParam)
+ val invokedType = MethodType.methodType(classOf[Function1ish[_, _]], capturedParamTypes)
+ val target = caller.findStatic(hostClass, accessorName, targetMethodType)
+ val site = LambdaMetafactory.metafactory(caller, "apply", invokedType, methodType, target, instantiatedMethodType)
+ site.getTarget.invokeWithArguments(captured: _*).asInstanceOf[Function1ish[A, B]]
+ }
+ def main(args: Array[String]) {
+ println(lambdaFactory(classOf[C], classOf[String], classOf[String], "accessor$1").apply("abc"))
+ println(lambdaFactory(classOf[C], classOf[String], classOf[String], "accessor$2", Array(classOf[String] -> "capture1")).apply("abc"))
+ println(lambdaFactory(classOf[C], classOf[String], classOf[String], "accessor$3", Array(classOf[C] -> new C)).apply("abc"))
+ println(lambdaFactory(Class.forName("T$class"), classOf[String], classOf[String], "accessor$4", Array(classOf[T] -> new T{})).apply("abc"))
+ }
+}