diff options
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/indylambda-boxing/test.scala | 7 | ||||
-rw-r--r-- | test/files/run/lambda-serialization.scala | 14 | ||||
-rw-r--r-- | test/files/run/reflection-mem-typecheck.scala | 4 | ||||
-rw-r--r-- | test/files/run/sammy_after_implicit_view.scala | 28 | ||||
-rw-r--r-- | test/files/run/sammy_cbn.scala | 9 | ||||
-rw-r--r-- | test/files/run/sammy_erasure_cce.scala | 22 | ||||
-rw-r--r-- | test/files/run/sammy_java8.flags | 1 | ||||
-rw-r--r-- | test/files/run/sammy_repeated.flags | 1 | ||||
-rw-r--r-- | test/files/run/sammy_repeated.scala | 8 | ||||
-rw-r--r-- | test/files/run/sammy_restrictions_LMF.check | 2 | ||||
-rw-r--r-- | test/files/run/sammy_restrictions_LMF.scala | 57 | ||||
-rw-r--r-- | test/files/run/sammy_return.scala | 14 | ||||
-rw-r--r-- | test/files/run/sammy_vararg_cbn.check (renamed from test/files/run/sammy_repeated.check) | 0 | ||||
-rw-r--r-- | test/files/run/sammy_vararg_cbn.scala | 12 | ||||
-rw-r--r-- | test/files/run/t8549.scala | 4 |
15 files changed, 166 insertions, 17 deletions
diff --git a/test/files/run/indylambda-boxing/test.scala b/test/files/run/indylambda-boxing/test.scala index cc0a460640..82f8d2f497 100644 --- a/test/files/run/indylambda-boxing/test.scala +++ b/test/files/run/indylambda-boxing/test.scala @@ -2,15 +2,16 @@ class Capture class Test { def test1 = (i: Int) => "" def test2 = (i: VC) => i - def test3 = (i: Int) => i + def test3 = (i: Int) => i // not adapted, specialized - def test4 = {val c = new Capture; (i: Int) => {(c, Test.this.toString); 42} } + def test4 = {val c = new Capture; (i: Int) => {(c, Test.this.toString); 42} } // not adapted, specialized def test5 = {val c = new Capture; (i: VC) => (c, Test.this.toString) } def test6 = {val c = new Capture; (i: Int) => (c, Test.this.toString) } def test7 = {val vc = new Capture; (i: Int) => vc } - def test8 = {val c = 42; (s: String) => (s, c)} + def test8 = {val c = 42; (s: String) => (s, c)} // not adapted def test9 = {val c = 42; (s: String) => ()} + def test10 = {(s: List[String]) => ()} } object Test { diff --git a/test/files/run/lambda-serialization.scala b/test/files/run/lambda-serialization.scala index 46b26d7c5e..0eee1193d7 100644 --- a/test/files/run/lambda-serialization.scala +++ b/test/files/run/lambda-serialization.scala @@ -1,8 +1,11 @@ import java.io.{ByteArrayInputStream, ObjectInputStream, ObjectOutputStream, ByteArrayOutputStream} +trait IntToString { def apply(i: Int): String } + object Test { def main(args: Array[String]): Unit = { - roundTrip + roundTrip() + roundTripIndySam() } def roundTrip(): Unit = { @@ -22,6 +25,15 @@ object Test { assert(serializeDeserialize(serializeDeserialize(specializedLambda)).apply(42) == 2) } + // lambda targeting a SAM, not a FunctionN (should behave the same way) + def roundTripIndySam(): Unit = { + val lambda: IntToString = (x: Int) => "yo!" * x + val reconstituted1 = serializeDeserialize(lambda).asInstanceOf[IntToString] + val reconstituted2 = serializeDeserialize(reconstituted1).asInstanceOf[IntToString] + assert(reconstituted1.apply(2) == "yo!yo!") + assert(reconstituted1.getClass == reconstituted2.getClass) + } + def serializeDeserialize[T <: AnyRef](obj: T) = { val buffer = new ByteArrayOutputStream val out = new ObjectOutputStream(buffer) diff --git a/test/files/run/reflection-mem-typecheck.scala b/test/files/run/reflection-mem-typecheck.scala index e3cabf689d..93ec1c937a 100644 --- a/test/files/run/reflection-mem-typecheck.scala +++ b/test/files/run/reflection-mem-typecheck.scala @@ -11,7 +11,9 @@ object Test extends MemoryTest { cm.mkToolBox() } - override def maxDelta = 10 + // I'm not sure this is a great way to test for memory leaks, + // since we're also testing how good the JVM's GC is, and this is not easily reproduced between machines/over time + override def maxDelta = 12 override def calcsPerIter = 8 override def calc() { var snippet = """ diff --git a/test/files/run/sammy_after_implicit_view.scala b/test/files/run/sammy_after_implicit_view.scala new file mode 100644 index 0000000000..a13a71e562 --- /dev/null +++ b/test/files/run/sammy_after_implicit_view.scala @@ -0,0 +1,28 @@ +trait MySam { def apply(x: Int): String } + +// check that SAM conversion happens after implicit view application +object Test extends App { + final val AnonFunClass = "$anon$" + final val LMFClass = "$$Lambda$" // LambdaMetaFactory names classes like this + + // if there's an implicit conversion, it does not takes precedence (because that's what dotty does) + def implicitSam() = { + import language.implicitConversions + var ok = true + implicit def fun2sam(fun: Int => String): MySam = { ok = false; new MySam { def apply(x: Int) = fun(x) } } + val className = (((x: Int) => x.toString): MySam).getClass.toString + assert(ok, "implicit conversion not called") + assert(!(className contains AnonFunClass), className) + assert(className contains LMFClass, className) + } + + // indirectly check that this sam type instance was created from a class spun up by LambdaMetaFactory + def justSammy() = { + val className = (((x: Int) => x.toString): MySam).getClass.toString + assert(!(className contains AnonFunClass), className) + assert(className contains LMFClass, className) + } + + implicitSam() + justSammy() +} diff --git a/test/files/run/sammy_cbn.scala b/test/files/run/sammy_cbn.scala new file mode 100644 index 0000000000..b84b2fd8e5 --- /dev/null +++ b/test/files/run/sammy_cbn.scala @@ -0,0 +1,9 @@ +trait F0[T] { def apply(): T } + +object Test extends App { + def delay[T](v: => T) = (v _): F0[T] + + // should not fail with ClassCastException: $$Lambda$6279/897871870 cannot be cast to F0 + // (also, should not say boe!) + delay(println("boe!")) +} diff --git a/test/files/run/sammy_erasure_cce.scala b/test/files/run/sammy_erasure_cce.scala new file mode 100644 index 0000000000..fb973befe4 --- /dev/null +++ b/test/files/run/sammy_erasure_cce.scala @@ -0,0 +1,22 @@ +trait F1 { + def apply(a: List[String]): String + def f1 = "f1" +} + +object Test extends App { + // Wrap the sam-targeting function in a context where the expected type is erased (identity's argument type erases to Object), + // so that Erasure can't tell that the types actually conform by looking only + // at an un-adorned Function tree and the expected type + // (because a function type needs no cast it the expected type is a SAM type), + // + // A correct implementation of Typers/Erasure tracks a Function's SAM target type directly + // (currently using an attachment for backwards compat), + // and not in the expected type (which was the case in my first attempt), + // as the expected type may lose its SAM status due to erasure. + // (In a sense, this need not be so, but erasure drops type parameters, + // so that identity's F1 type argument cannot be propagated to its argument type.) + def foo = identity[F1]((as: List[String]) => as.head) + + // check that this doesn't CCE's + foo.f1 +} diff --git a/test/files/run/sammy_java8.flags b/test/files/run/sammy_java8.flags deleted file mode 100644 index 48fd867160..0000000000 --- a/test/files/run/sammy_java8.flags +++ /dev/null @@ -1 +0,0 @@ --Xexperimental diff --git a/test/files/run/sammy_repeated.flags b/test/files/run/sammy_repeated.flags deleted file mode 100644 index e1b37447c9..0000000000 --- a/test/files/run/sammy_repeated.flags +++ /dev/null @@ -1 +0,0 @@ --Xexperimental
\ No newline at end of file diff --git a/test/files/run/sammy_repeated.scala b/test/files/run/sammy_repeated.scala deleted file mode 100644 index c24dc41909..0000000000 --- a/test/files/run/sammy_repeated.scala +++ /dev/null @@ -1,8 +0,0 @@ -trait RepeatedSink { def accept(a: Any*): Unit } - -object Test { - def main(args: Array[String]): Unit = { - val f: RepeatedSink = (a) => println(a) - f.accept(1) - } -}
\ No newline at end of file diff --git a/test/files/run/sammy_restrictions_LMF.check b/test/files/run/sammy_restrictions_LMF.check new file mode 100644 index 0000000000..6ed281c757 --- /dev/null +++ b/test/files/run/sammy_restrictions_LMF.check @@ -0,0 +1,2 @@ +1 +1 diff --git a/test/files/run/sammy_restrictions_LMF.scala b/test/files/run/sammy_restrictions_LMF.scala new file mode 100644 index 0000000000..aa49e14113 --- /dev/null +++ b/test/files/run/sammy_restrictions_LMF.scala @@ -0,0 +1,57 @@ +trait T[@specialized A] { def apply(a: A): A } +trait TInt extends T[Int] + +trait TWithVal { val x: Any = 1; def apply(x: Int): String } + +trait TImpure { def apply(x: Int): String ; println(1) } + +trait Println { println(1) } +trait TImpureSuper extends Println { def apply(x: Int): String } + +class C +trait A extends C +trait B extends A +trait TClassParent extends B { def apply(x: Int): String } + +object Test extends App { + final val AnonFunClass = "$anonfun$" + final val LMFClass = "$$Lambda$" // LambdaMetaFactory names classes like this + + private def LMF(f: Any): Unit = { + val className = f.getClass.toString + assert(!(className contains AnonFunClass), className) + assert((className contains LMFClass), className) + } + + private def notLMF(f: Any): Unit = { + val className = f.getClass.toString + assert((className contains AnonFunClass), className) + assert(!(className contains LMFClass), className) + } + + // Check that we expand the SAM of a type that is specialized. + // This is an implementation restriction -- the current specialization scheme is not + // amenable to using LambdaMetaFactory to spin up subclasses. + // Since the generic method is abstract, and the specialized ones are concrete, + // specialization is rendered moot because we cannot implement the specialized method + // with the lambda using LMF. + + // not LMF if specialized at this type + notLMF((x => x): T[Int]) + // not LMF if specialized at this type (via subclass) + notLMF((x => x): TInt) + // LMF ok if not specialized at this type + LMF((x => x): T[String]) + + // traits with a val member also cannot be instantiated by LMF + val fVal: TWithVal = (x => "a") + notLMF(fVal) + assert(fVal.x == 1) + + notLMF((x => "a"): TImpure) + notLMF((x => "a"): TImpureSuper) + + val fClassParent: TClassParent = x => "a" + notLMF(fClassParent) + assert(fClassParent(1) == "a") +} diff --git a/test/files/run/sammy_return.scala b/test/files/run/sammy_return.scala new file mode 100644 index 0000000000..e959619dd1 --- /dev/null +++ b/test/files/run/sammy_return.scala @@ -0,0 +1,14 @@ +trait Fun[A, B] { def apply(a: A): B } +class PF[A, B] { def runWith[U](action: Fun[B, U]): Fun[A, Boolean] = a => {action(a.asInstanceOf[B]); true} } + +class TO[A](x: A) { + def foreach[U](f: Fun[A, U]): U = f(x) + def collectFirst[B](pf: PF[A, B]): Option[B] = { + foreach(pf.runWith(b => return Some(b))) + None + } +} + +object Test extends App { + assert(new TO("a").collectFirst(new PF[String, String]).get == "a") +}
\ No newline at end of file diff --git a/test/files/run/sammy_repeated.check b/test/files/run/sammy_vararg_cbn.check index 1cff0f067c..1cff0f067c 100644 --- a/test/files/run/sammy_repeated.check +++ b/test/files/run/sammy_vararg_cbn.check diff --git a/test/files/run/sammy_vararg_cbn.scala b/test/files/run/sammy_vararg_cbn.scala new file mode 100644 index 0000000000..e5b49498ea --- /dev/null +++ b/test/files/run/sammy_vararg_cbn.scala @@ -0,0 +1,12 @@ +trait SamRepeated { def accept(a: Any*): Unit } +trait SamByName { def accept(a: => Any): (Any, Any) } + +object Test extends App { + val rep: SamRepeated = (a) => println(a) + rep.accept(1) + + val nam: SamByName = (a) => (a, a) + var v = 0 + assert(nam.accept({v += 1; v}) == (1, 2)) + assert(v == 2, "by name arg should be evaluated twice") +} diff --git a/test/files/run/t8549.scala b/test/files/run/t8549.scala index 233a05dee1..e2d0d335b0 100644 --- a/test/files/run/t8549.scala +++ b/test/files/run/t8549.scala @@ -79,7 +79,7 @@ object Test extends App { } } - // Generated on 20150925-14:41:27 with Scala version 2.12.0-20150924-125956-fd5994f397) + // Generated on 20160328-17:47:35 with Scala version 2.12.0-20160328-174205-d46145c) overwrite.foreach(updateComment) check(Some(1))("rO0ABXNyAApzY2FsYS5Tb21lESLyaV6hi3QCAAFMAAF4dAASTGphdmEvbGFuZy9PYmplY3Q7eHIADHNjYWxhLk9wdGlvbv5pN/3bDmZ0AgAAeHBzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAQ==") @@ -176,7 +176,7 @@ object Test extends App { // check(mutable.ArrayBuffer(1, 2, 3))( "rO0ABXNyACRzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuQXJyYXlCdWZmZXIVOLBTg4KOcwIAA0kAC2luaXRpYWxTaXplSQAFc2l6ZTBbAAVhcnJheXQAE1tMamF2YS9sYW5nL09iamVjdDt4cAAAABAAAAADdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAAEHNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAABc3EAfgAFAAAAAnNxAH4ABQAAAANwcHBwcHBwcHBwcHBw") // TODO SI-8576 Uninitialized field under -Xcheckinit // check(mutable.ArraySeq(1, 2, 3))( "rO0ABXNyACFzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuQXJyYXlTZXEVP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