diff options
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/delambdafy_uncurry_byname_inline.check | 2 | ||||
-rw-r--r-- | test/files/run/delambdafy_uncurry_inline.check | 2 | ||||
-rw-r--r-- | test/files/run/global-showdef.check | 8 | ||||
-rw-r--r-- | test/files/run/global-showdef.scala | 52 | ||||
-rw-r--r-- | test/files/run/repl-javap-lambdas.scala | 23 | ||||
-rw-r--r-- | test/files/run/repl-javap-memfun.scala | 4 | ||||
-rw-r--r-- | test/files/run/t4950.check | 9 | ||||
-rw-r--r-- | test/files/run/t4950.scala | 12 | ||||
-rw-r--r-- | test/files/run/t6028.check | 4 | ||||
-rw-r--r-- | test/files/run/t6541-option.scala | 19 | ||||
-rw-r--r-- | test/files/run/t6541.flags | 1 | ||||
-rw-r--r-- | test/files/run/t6541.scala | 25 | ||||
-rw-r--r-- | test/files/run/t6555.check | 2 | ||||
-rw-r--r-- | test/files/run/t8893.scala | 40 | ||||
-rw-r--r-- | test/files/run/t8893b.scala | 15 | ||||
-rw-r--r-- | test/files/run/t8960.scala | 66 | ||||
-rw-r--r-- | test/files/run/xMigration.check | 49 | ||||
-rw-r--r-- | test/files/run/xMigration.scala | 19 |
18 files changed, 311 insertions, 41 deletions
diff --git a/test/files/run/delambdafy_uncurry_byname_inline.check b/test/files/run/delambdafy_uncurry_byname_inline.check index 0dc69b379a..d96a995f44 100644 --- a/test/files/run/delambdafy_uncurry_byname_inline.check +++ b/test/files/run/delambdafy_uncurry_byname_inline.check @@ -7,7 +7,7 @@ package <empty> { }; def bar(x: () => Int): Int = x.apply(); def foo(): Int = Foo.this.bar({ - @SerialVersionUID(0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction0[Int] with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction0[Int] with Serializable { def <init>(): <$anon: () => Int> = { $anonfun.super.<init>(); () diff --git a/test/files/run/delambdafy_uncurry_inline.check b/test/files/run/delambdafy_uncurry_inline.check index e2b024b462..5521cc4a2c 100644 --- a/test/files/run/delambdafy_uncurry_inline.check +++ b/test/files/run/delambdafy_uncurry_inline.check @@ -7,7 +7,7 @@ package <empty> { }; def bar(): Unit = { val f: Int => Int = { - @SerialVersionUID(0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1[Int,Int] with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1[Int,Int] with Serializable { def <init>(): <$anon: Int => Int> = { $anonfun.super.<init>(); () diff --git a/test/files/run/global-showdef.check b/test/files/run/global-showdef.check index 4c2fd41a1a..4ac96b4315 100644 --- a/test/files/run/global-showdef.check +++ b/test/files/run/global-showdef.check @@ -1,14 +1,14 @@ <<-- class foo.bar.Bippy after phase 'typer' -->> def showdefTestMemberClass1: Int +<<-- object foo.bar.Bippy after phase 'typer' -->> + def showdefTestMemberObject2: String <<-- type foo.bar.Bippy.BippyType after phase 'typer' -->> def showdefTestMemberType1: Unit +<<-- object foo.bar.Bippy.Boppity.Boo after phase 'typer' -->> + def showdefTestMemberObject1: String <<-- type foo.bar.Bippy.BippyType after phase 'typer' -->> def showdefTestMemberType2: Unit <<-- class foo.bar.Bippy.Boppity after phase 'typer' -->> def showdefTestMemberClass2: Int <<-- class foo.bar.Bippy.Boppity.Boo after phase 'typer' -->> def showdefTestMemberClass3: Int -<<-- object foo.bar.Bippy after phase 'typer' -->> - def showdefTestMemberObject2: String -<<-- object foo.bar.Bippy.Boppity.Boo after phase 'typer' -->> - def showdefTestMemberObject1: String diff --git a/test/files/run/global-showdef.scala b/test/files/run/global-showdef.scala index 1d4891fd1f..276fcc1e7c 100644 --- a/test/files/run/global-showdef.scala +++ b/test/files/run/global-showdef.scala @@ -1,11 +1,10 @@ -import scala.tools.nsc._ -import scala.reflect.io.AbstractFile +import scala.tools.partest.DirectTest import scala.tools.nsc.util.stringFromStream -import scala.reflect.internal.util.{ SourceFile, BatchSourceFile } -import scala.tools.nsc.reporters.ConsoleReporter -object Test { - val src: SourceFile = new BatchSourceFile("src", """ +object Test extends DirectTest { + override def extraSettings: String = "-usejavacp -Yshow:typer -Ystop-after:typer" + + override def code = """ package foo.bar class Bippy { @@ -32,39 +31,28 @@ object Bippy { def showdefTestMemberObject2 = "abc" } - """) + """ + + override def show(): Unit = { + val classes = List("Bippy", "Bippy#BippyType", "Bippy.BippyType", "Bippy#Boppity", "Bippy#Boppity#Boo") + val objects = List("Bippy", "Bippy#Boppity#Boo") + + def interesting(line: String) = (line contains "def showdefTestMember") || (line startsWith "<<-- ") - def mkCompiler(args: String*) = { - val settings = new Settings() - val command = new CompilerCommand("-usejavacp" :: args.toList, settings) + def run(args: String*) = slurp(args: _*).lines filter interesting foreach println - new Global(settings) + classes.zipAll(objects, "", "") foreach { + case (c, "") => run("-Xshow-class", c) + case (c, o) => run("-Xshow-class", c, "-Xshow-object", o) + } } - def slurp(body: => Unit): String = stringFromStream { stream => + // slurp the compilation result + def slurp(args: String*): String = stringFromStream { stream => Console.withOut(stream) { Console.withErr(stream) { - body + compile(args: _*) } } } - def lines(args: String*): List[String] = { - val output = slurp { - val compiler = mkCompiler(args: _*) - val run = new compiler.Run() - run.compileSources(List(src)) - } - output.lines.toList - } - def showClass(name: String) = lines("-Yshow:typer", "-Xshow-class", name) - def showObject(name: String) = lines("-Yshow:typer", "-Xshow-object", name) - - def show(xs: List[String]) = { - xs filter (x => (x contains "def showdefTestMember") || (x startsWith "<<-- ")) foreach println - } - - def main(args: Array[String]) { - show(List("Bippy", "Bippy#BippyType", "Bippy.BippyType", "Bippy#Boppity", "Bippy#Boppity#Boo") flatMap showClass) - show(List("Bippy", "Bippy#Boppity#Boo") flatMap showObject) - } } 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) diff --git a/test/files/run/t4950.check b/test/files/run/t4950.check new file mode 100644 index 0000000000..3f3a302b62 --- /dev/null +++ b/test/files/run/t4950.check @@ -0,0 +1,9 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> val 1 = 2 +scala.MatchError: 2 (of class java.lang.Integer) + +scala> val List(1) = List(1) + +scala> :quit diff --git a/test/files/run/t4950.scala b/test/files/run/t4950.scala new file mode 100644 index 0000000000..cef06027bf --- /dev/null +++ b/test/files/run/t4950.scala @@ -0,0 +1,12 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + // Filter out the abbreviated stacktrace "... X elided" + // because the number seems to differ between versions/platforms/... + override def show = eval() filterNot (_ contains "elided") foreach println + def code = +""" +val 1 = 2 +val List(1) = List(1) +""" +} diff --git a/test/files/run/t6028.check b/test/files/run/t6028.check index 55ff42d8d7..edc8b22d6d 100644 --- a/test/files/run/t6028.check +++ b/test/files/run/t6028.check @@ -24,7 +24,7 @@ package <empty> { (new <$anon: Function0>(T.this, tryyParam, tryyLocal): Function0) } }; - @SerialVersionUID(0) final <synthetic> class $anonfun$foo$1 extends scala.runtime.AbstractFunction0$mcI$sp with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun$foo$1 extends scala.runtime.AbstractFunction0$mcI$sp with Serializable { def <init>($outer: T, methodParam$1: Int, methodLocal$1: Int): <$anon: Function0> = { $anonfun$foo$1.super.<init>(); () @@ -60,7 +60,7 @@ package <empty> { }; scala.this.Predef.print(scala.Int.box(barParam$1)) }; - @SerialVersionUID(0) final <synthetic> class $anonfun$tryy$1 extends scala.runtime.AbstractFunction0$mcV$sp with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun$tryy$1 extends scala.runtime.AbstractFunction0$mcV$sp with Serializable { def <init>($outer: T, tryyParam$1: Int, tryyLocal$1: runtime.IntRef): <$anon: Function0> = { $anonfun$tryy$1.super.<init>(); () diff --git a/test/files/run/t6541-option.scala b/test/files/run/t6541-option.scala new file mode 100644 index 0000000000..2c10c9e09d --- /dev/null +++ b/test/files/run/t6541-option.scala @@ -0,0 +1,19 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ +:setting -Xsource:2.12 +case class C12(clazz: Class[_]) +val o: Option[Class[T] forSome { type T}] = C12.unapply(C12(classOf[String])) + +:setting -Xsource:2.11 +import scala.language.existentials +case class C11(clazz: Class[_]) +val o: Option[Class[T]] forSome { type T } = C11.unapply(C11(classOf[String])) + """ + + override def show() = { + val r = eval().mkString("\n") + assert(!(r.contains("warning") || r.contains("error")), r) + } +} diff --git a/test/files/run/t6541.flags b/test/files/run/t6541.flags new file mode 100644 index 0000000000..68d0ddfec2 --- /dev/null +++ b/test/files/run/t6541.flags @@ -0,0 +1 @@ +-feature -Xfatal-warnings -Xsource:2.12
\ No newline at end of file diff --git a/test/files/run/t6541.scala b/test/files/run/t6541.scala new file mode 100644 index 0000000000..f127143691 --- /dev/null +++ b/test/files/run/t6541.scala @@ -0,0 +1,25 @@ +class A +class B[T](x: T) +case class C(a: A, b: B[_]) + +case class D(a: A, b: B[_]*) + +case class E(c: Class[_]) + +object Test extends App { + def f1(c: C) = c match { + case C(a, b) => () + } + + def f2(d: D) = d match { + case D(a, b1, b2) => () + } + + def f3(e: E) = e match { + case E(c) => () + } + + f1(C(new A, new B(1))) + f2(D(new A, new B(1), new B(2))) + f3(E(classOf[E])) +} diff --git a/test/files/run/t6555.check b/test/files/run/t6555.check index 9ac115a13f..e3b467ce7c 100644 --- a/test/files/run/t6555.check +++ b/test/files/run/t6555.check @@ -6,7 +6,7 @@ package <empty> { () }; private[this] val f: Int => Int = { - @SerialVersionUID(0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1$mcII$sp with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1$mcII$sp with Serializable { def <init>(): <$anon: Int => Int> = { $anonfun.super.<init>(); () diff --git a/test/files/run/t8893.scala b/test/files/run/t8893.scala new file mode 100644 index 0000000000..6fef8ae912 --- /dev/null +++ b/test/files/run/t8893.scala @@ -0,0 +1,40 @@ +import annotation.tailrec + +object Test { + def a(): Option[String] = Some("a") + + def test1: Any = { + a() match { + case Some(b1) => + a() match { + case Some(b2) => + @tailrec + def tick(i: Int): Unit = if (i < 0) () else tick(i - 1) + tick(10000000) // testing that this doesn't SOE + case None => None + } + case None => None + } + } + + def test2: Any = { + a() match { + case Some(b1) => + a() match { + case Some(b2) => + @tailrec + def tick(i: Int): Unit = if (i < 0) () else tick(i - 1) + tick(10000000) // testing that this doesn't SOE + case None => test1 + } + case None => + test1 // not a tail call + test1 + } + } + + def main(args: Array[String]) { + test1 + test2 + } +} diff --git a/test/files/run/t8893b.scala b/test/files/run/t8893b.scala new file mode 100644 index 0000000000..19120871aa --- /dev/null +++ b/test/files/run/t8893b.scala @@ -0,0 +1,15 @@ +// Testing that recursive calls in tail positions are replaced with +// jumps, even though the method contains recursive calls outside +// of the tail position. +object Test { + def tick(i : Int): Unit = + if (i == 0) () + else if (i == 42) { + tick(0) /*not in tail posiiton*/ + tick(i - 1) + } else tick(i - 1) + + def main(args: Array[String]): Unit = { + tick(1000000) + } +} diff --git a/test/files/run/t8960.scala b/test/files/run/t8960.scala new file mode 100644 index 0000000000..c6bcd0770c --- /dev/null +++ b/test/files/run/t8960.scala @@ -0,0 +1,66 @@ +object Test extends App { + def test(o: AnyRef, sp: Boolean = false) = { + if (sp) assert(o.getClass.getSuperclass.getName contains "$sp") + val Some(f) = o.getClass.getDeclaredFields.find(_.getName == "serialVersionUID") + assert(f.getLong(null) == 0l) + } + + test(() => (), sp = true) + test(() => 1, sp = true) + test(() => "") + + test((x: Int) => x, sp = true) + test((x: Boolean) => x) + test((x: Int) => "") + + test((x1: Int, x2: Int) => 0d, sp = true) + test((x1: Int, x2: AnyRef) => 0d) + test((x1: Any, x2: Any) => x1) + + // scala> println((for (i <- 3 to 22) yield (for (j <- 1 to i) yield s"x$j: Int").mkString(" test((", ", ", ") => x1)")).mkString("\n")) + + test((x1: Int, x2: Int, x3: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) => x1) + + test({ + case x: Int => x + }: PartialFunction[Int, Int], sp = true) + + test({ + case x: Int => x + }: PartialFunction[Any, Any]) + + test({ + case x: Int => () + }: PartialFunction[Int, Unit], sp = true) + + test({ + case x: String => 1 + }: PartialFunction[String, Int]) + + test({ + case x: String => () + }: PartialFunction[String, Unit]) + + test({ + case x: String => x + }: PartialFunction[String, String]) +} diff --git a/test/files/run/xMigration.check b/test/files/run/xMigration.check new file mode 100644 index 0000000000..378f7bb6c3 --- /dev/null +++ b/test/files/run/xMigration.check @@ -0,0 +1,49 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> Map(1 -> "eis").values // no warn +res0: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:none + +scala> Map(1 -> "eis").values // no warn +res1: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:any + +scala> Map(1 -> "eis").values // warn +<console>:8: warning: method values in trait MapLike has changed semantics in version 2.8.0: +`values` returns `Iterable[B]` rather than `Iterator[B]`. + Map(1 -> "eis").values // warn + ^ +res2: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:2.8 + +scala> Map(1 -> "eis").values // no warn +res3: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:2.7 + +scala> Map(1 -> "eis").values // warn +<console>:8: warning: method values in trait MapLike has changed semantics in version 2.8.0: +`values` returns `Iterable[B]` rather than `Iterator[B]`. + Map(1 -> "eis").values // warn + ^ +res4: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:2.11 + +scala> Map(1 -> "eis").values // no warn +res5: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration // same as :any + +scala> Map(1 -> "eis").values // warn +<console>:8: warning: method values in trait MapLike has changed semantics in version 2.8.0: +`values` returns `Iterable[B]` rather than `Iterator[B]`. + Map(1 -> "eis").values // warn + ^ +res6: Iterable[String] = MapLike(eis) + +scala> :quit diff --git a/test/files/run/xMigration.scala b/test/files/run/xMigration.scala new file mode 100644 index 0000000000..688e878397 --- /dev/null +++ b/test/files/run/xMigration.scala @@ -0,0 +1,19 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ +Map(1 -> "eis").values // no warn +:setting -Xmigration:none +Map(1 -> "eis").values // no warn +:setting -Xmigration:any +Map(1 -> "eis").values // warn +:setting -Xmigration:2.8 +Map(1 -> "eis").values // no warn +:setting -Xmigration:2.7 +Map(1 -> "eis").values // warn +:setting -Xmigration:2.11 +Map(1 -> "eis").values // no warn +:setting -Xmigration // same as :any +Map(1 -> "eis").values // warn + """ +} |