From 5b532e927241bfaea4aa9b36e32ff3a0deb1ae15 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Thu, 14 Nov 2013 00:22:10 -0800 Subject: Revived tests that once depended on xml I was a bit overzealous in moving stuff over to scala-xml in 9c50dd5274 These were all compiler tests that accidentally touched on xml. I've tried to delicately decouple them so they can roam the scalac pastures as intended. --- test/files/pos/t1014.scala | 16 +++++++ test/files/pos/t1203a.scala | 13 ++++++ test/files/pos/t2698.scala | 14 +++++++ test/files/pos/t3160.scala | 6 +++ test/files/pos/t6201.scala | 19 +++++++++ test/files/run/fors.check | 28 +++++++++++++ test/files/run/fors.scala | 84 +++++++++++++++++++++++++++++++++++++ test/files/run/repl-backticks.check | 2 + test/files/run/repl-backticks.scala | 18 ++++++++ test/files/run/t1500.check | 3 ++ test/files/run/t1500.scala | 46 ++++++++++++++++++++ test/files/run/t1501.check | 3 ++ test/files/run/t1501.scala | 56 +++++++++++++++++++++++++ test/files/run/t4124.check | 4 ++ test/files/run/t4124.scala | 24 +++++++++++ 15 files changed, 336 insertions(+) create mode 100644 test/files/pos/t1014.scala create mode 100644 test/files/pos/t1203a.scala create mode 100644 test/files/pos/t2698.scala create mode 100644 test/files/pos/t3160.scala create mode 100644 test/files/pos/t6201.scala create mode 100644 test/files/run/fors.check create mode 100644 test/files/run/fors.scala create mode 100644 test/files/run/repl-backticks.check create mode 100644 test/files/run/repl-backticks.scala create mode 100644 test/files/run/t1500.check create mode 100644 test/files/run/t1500.scala create mode 100644 test/files/run/t1501.check create mode 100644 test/files/run/t1501.scala create mode 100644 test/files/run/t4124.check create mode 100644 test/files/run/t4124.scala diff --git a/test/files/pos/t1014.scala b/test/files/pos/t1014.scala new file mode 100644 index 0000000000..6fb7f7ba49 --- /dev/null +++ b/test/files/pos/t1014.scala @@ -0,0 +1,16 @@ +class NodeSeq +class Elem extends NodeSeq + +class EO extends App with Moo { + // return type is Flog, inherited from overridden method. + // implicit conversions are applied because expected type `pt` is `Flog` when `computeType(rhs, pt)`. + def cat = (??? : Elem) + + implicit def nodeSeqToFlog(in: Elem): Flog = new Flog(in) +} + +trait Moo { + def cat: Flog +} + +class Flog(val in: NodeSeq) diff --git a/test/files/pos/t1203a.scala b/test/files/pos/t1203a.scala new file mode 100644 index 0000000000..cf5ab9fba0 --- /dev/null +++ b/test/files/pos/t1203a.scala @@ -0,0 +1,13 @@ +class Node +object NodeSeq { + implicit def seqToNodeSeq(s: Seq[Node]): NodeSeq = ??? +} +abstract class NodeSeq extends collection.immutable.Seq[Node] + +case class ant(t: String) extends scala.annotation.Annotation +object Test { + def main(args: Array[String]): Unit = { + val a: NodeSeq @ant("12") = Nil + println(a) + } +} diff --git a/test/files/pos/t2698.scala b/test/files/pos/t2698.scala new file mode 100644 index 0000000000..bce02e48b3 --- /dev/null +++ b/test/files/pos/t2698.scala @@ -0,0 +1,14 @@ +class WordExp { + abstract class Label + type _labelT <: Label +} + +import scala.collection._ + +abstract class S2 { + val lang: WordExp + type __labelT = lang._labelT + + var deltaq: Array[__labelT] = _ + def delta1 = immutable.Map(deltaq.zipWithIndex: _*) +} diff --git a/test/files/pos/t3160.scala b/test/files/pos/t3160.scala new file mode 100644 index 0000000000..cc007dc014 --- /dev/null +++ b/test/files/pos/t3160.scala @@ -0,0 +1,6 @@ +import scala.collection.mutable._ +class Node + +class A { + def f(x: Node): Node = ??? +} diff --git a/test/files/pos/t6201.scala b/test/files/pos/t6201.scala new file mode 100644 index 0000000000..d4e5bce03a --- /dev/null +++ b/test/files/pos/t6201.scala @@ -0,0 +1,19 @@ +// probably needs xml's weirdness to reproduce +// (specifically, _root_.scala.xml.Null being in the root package) +class Elem + +class Test { + def elem: Elem = ??? + + class Foo1 { + def must(x: Elem) = () + } + + class Foo2 { + def must(x: Int) = () + } + implicit def toFoo1(s: Elem) = new Foo1() + implicit def toFoo2(s: Elem) = new Foo2() + + def is: Unit = { (elem) } +} \ No newline at end of file diff --git a/test/files/run/fors.check b/test/files/run/fors.check new file mode 100644 index 0000000000..b459f00b49 --- /dev/null +++ b/test/files/run/fors.check @@ -0,0 +1,28 @@ + +testOld +1 2 3 +2 +2 +3 +1 2 3 +1 2 3 +0 1 2 3 4 5 6 7 8 9 +0 2 4 6 8 +0 2 4 6 8 +a b c +b c +b c + +testNew +3 +1 2 3 +1 2 3 +0 1 2 3 4 5 6 7 8 9 +0 2 4 6 8 +0 2 4 6 8 +0 2 4 6 8 +0 2 4 6 8 +0 2 4 6 8 +0 2 4 6 8 +0 2 4 6 8 +a b c diff --git a/test/files/run/fors.scala b/test/files/run/fors.scala new file mode 100644 index 0000000000..c778df3e24 --- /dev/null +++ b/test/files/run/fors.scala @@ -0,0 +1,84 @@ +//############################################################################ +// for-comprehensions (old and new syntax) +//############################################################################ + +//############################################################################ + +object Test extends App { + val xs = List(1, 2, 3) + val ys = List('a, 'b, 'c) + + def it = 0 until 10 + + val ar = "abc".toCharArray + + /////////////////// old syntax /////////////////// + + def testOld { + println("\ntestOld") + + // lists + for (x <- xs) print(x + " "); println + for (x <- xs; + if x % 2 == 0) print(x + " "); println + for {x <- xs + if x % 2 == 0} print(x + " "); println + var n = 0 + for (_ <- xs) n += 1; println(n) + for ((x, y) <- xs zip ys) print(x + " "); println + for (p @ (x, y) <- xs zip ys) print(p._1 + " "); println + + // iterators + for (x <- it) print(x + " "); println + for (x <- it; + if x % 2 == 0) print(x + " "); println + for {x <- it + if x % 2 == 0} print(x + " "); println + + // arrays + for (x <- ar) print(x + " "); println + for (x <- ar; + if x.toInt > 97) print(x + " "); println + for {x <- ar + if x.toInt > 97} print(x + " "); println + + } + + /////////////////// new syntax /////////////////// + + def testNew { + println("\ntestNew") + + // lists + var n = 0 + for (_ <- xs) n += 1; println(n) + for ((x, y) <- xs zip ys) print(x + " "); println + for (p @ (x, y) <- xs zip ys) print(p._1 + " "); println + + // iterators + for (x <- it) print(x + " "); println + for (x <- it if x % 2 == 0) print(x + " "); println + for (x <- it; if x % 2 == 0) print(x + " "); println + for (x <- it; + if x % 2 == 0) print(x + " "); println + for (x <- it + if x % 2 == 0) print(x + " "); println + for {x <- it + if x % 2 == 0} print(x + " "); println + for (x <- it; + y = 2 + if x % y == 0) print(x + " "); println + for {x <- it + y = 2 + if x % y == 0} print(x + " "); println + + // arrays + for (x <- ar) print(x + " "); println + + } + + //////////////////////////////////////////////////// + + testOld + testNew +} diff --git a/test/files/run/repl-backticks.check b/test/files/run/repl-backticks.check new file mode 100644 index 0000000000..c0561abd7c --- /dev/null +++ b/test/files/run/repl-backticks.check @@ -0,0 +1,2 @@ +import java.lang.Thread.`yield` +import scala.`package`.Throwable diff --git a/test/files/run/repl-backticks.scala b/test/files/run/repl-backticks.scala new file mode 100644 index 0000000000..e40a8bc662 --- /dev/null +++ b/test/files/run/repl-backticks.scala @@ -0,0 +1,18 @@ +import scala.tools.nsc._ + +object Test { + val testCode = """ + import java.lang.Thread.`yield` + import scala.`package`.Throwable + + `yield` + """ + + def main(args: Array[String]) { + val settings = new Settings() + settings.classpath.value = System.getProperty("java.class.path") + val repl = new interpreter.IMain(settings) + repl.interpret(testCode) + } +} + diff --git a/test/files/run/t1500.check b/test/files/run/t1500.check new file mode 100644 index 0000000000..94a169333b --- /dev/null +++ b/test/files/run/t1500.check @@ -0,0 +1,3 @@ +defined class posingAs +resolve: [A, B](x: A @posingAs[B])B +x: Any = 7 diff --git a/test/files/run/t1500.scala b/test/files/run/t1500.scala new file mode 100644 index 0000000000..30c026f70f --- /dev/null +++ b/test/files/run/t1500.scala @@ -0,0 +1,46 @@ +import scala.tools.nsc._ + +object Test { + + /** + * Type inference overlooks constraints posed by type parameters in annotations on types. + */ + + val testCode = """ + + class posingAs[A] extends annotation.TypeConstraint + + def resolve[A,B](x: A @posingAs[B]): B = x.asInstanceOf[B] + + val x = resolve(7: @posingAs[Any]) + + """ + + def main(args: Array[String]) { + + val settings = new Settings() + settings.classpath.value = System.getProperty("java.class.path") + val tool = new interpreter.IMain(settings) + val global = tool.global + + import global._ + import definitions._ + + object checker extends AnnotationChecker { + + /** Check annotations to decide whether tpe1 <:< tpe2 */ + def annotationsConform(tpe1: Type, tpe2: Type): Boolean = { + + tpe1.annotations.forall(a1 => tpe2.annotations.forall(a2 => a1.atp <:< a2.atp)) + + } + } + + global.addAnnotationChecker(checker) + + tool.interpret(testCode) + + } + +} + diff --git a/test/files/run/t1501.check b/test/files/run/t1501.check new file mode 100644 index 0000000000..f0fa9112a5 --- /dev/null +++ b/test/files/run/t1501.check @@ -0,0 +1,3 @@ +defined class xyz +loopWhile: [T](cond: => Boolean)(body: => Unit @xyz[T])Unit @xyz[T] +test: ()Unit @xyz[Int] diff --git a/test/files/run/t1501.scala b/test/files/run/t1501.scala new file mode 100644 index 0000000000..ca6bf357fb --- /dev/null +++ b/test/files/run/t1501.scala @@ -0,0 +1,56 @@ +import scala.tools.nsc._ + +object Test { + + /** + * ... + */ + + val testCode = """ + + class xyz[A] extends annotation.TypeConstraint + + def loopWhile[T](cond: =>Boolean)(body: =>(Unit @xyz[T])): Unit @ xyz[T] = {{ + if (cond) {{ + body + loopWhile[T](cond)(body) + }} + }} + + def test() = {{ + var x = 7 + loopWhile(x != 0) {{ + x = x - 1 + (): @xyz[Int] + }} + }} + + """ + + def main(args: Array[String]) { + val settings = new Settings() + settings.classpath.value = System.getProperty("java.class.path") + val tool = new interpreter.IMain(settings) + val global = tool.global + + import global._ + import definitions._ + + object checker extends AnnotationChecker { + + /** Check annotations to decide whether tpe1 <:< tpe2 */ + def annotationsConform(tpe1: Type, tpe2: Type): Boolean = { + + tpe1.annotations.forall(a1 => tpe2.annotations.forall(a2 => a1.atp <:< a2.atp)) + + } + } + + global.addAnnotationChecker(checker) + + tool.interpret(testCode) + + } + +} + diff --git a/test/files/run/t4124.check b/test/files/run/t4124.check new file mode 100644 index 0000000000..66a0092d93 --- /dev/null +++ b/test/files/run/t4124.check @@ -0,0 +1,4 @@ +hi +hi +bye +bye diff --git a/test/files/run/t4124.scala b/test/files/run/t4124.scala new file mode 100644 index 0000000000..9f35b57ce3 --- /dev/null +++ b/test/files/run/t4124.scala @@ -0,0 +1,24 @@ +import xml.Node + +object Test extends App { + val body: Node = hi + println ((body: AnyRef, "foo") match { + case (node: Node, "bar") => "bye" + case (ser: Serializable, "foo") => "hi" + }) + + println ((body, "foo") match { + case (node: Node, "bar") => "bye" + case (ser: Serializable, "foo") => "hi" + }) + + println ((body: AnyRef, "foo") match { + case (node: Node, "foo") => "bye" + case (ser: Serializable, "foo") => "hi" + }) + + println ((body: AnyRef, "foo") match { + case (node: Node, "foo") => "bye" + case (ser: Serializable, "foo") => "hi" + }) +} -- cgit v1.2.3