diff options
-rw-r--r-- | test/files/neg/bug283.check | 4 | ||||
-rw-r--r-- | test/files/neg/bug283.scala | 8 | ||||
-rw-r--r-- | test/files/pos/304.scala | 5 | ||||
-rw-r--r-- | test/files/pos/bug304.scala | 5 | ||||
-rwxr-xr-x | test/files/pos/viewtest1.scala | 41 | ||||
-rwxr-xr-x | test/files/pos/viewtest2.scala | 77 |
6 files changed, 140 insertions, 0 deletions
diff --git a/test/files/neg/bug283.check b/test/files/neg/bug283.check new file mode 100644 index 0000000000..ca9c9f0d13 --- /dev/null +++ b/test/files/neg/bug283.check @@ -0,0 +1,4 @@ +bug283.scala:7: illegal cyclic reference involving constructor A + type A[t1] = P[A[t1],t1]; + ^ +one error found diff --git a/test/files/neg/bug283.scala b/test/files/neg/bug283.scala new file mode 100644 index 0000000000..0edcc6c751 --- /dev/null +++ b/test/files/neg/bug283.scala @@ -0,0 +1,8 @@ +// bug contribution #12 + +trait P[a<:P[a,t1],t1]:a; + +object X +{ + type A[t1] = P[A[t1],t1]; +} diff --git a/test/files/pos/304.scala b/test/files/pos/304.scala new file mode 100644 index 0000000000..607a115db2 --- /dev/null +++ b/test/files/pos/304.scala @@ -0,0 +1,5 @@ +object O { + def f1 = -1; + def f2 = 0-1; + def f3 = f1 + f2; +} diff --git a/test/files/pos/bug304.scala b/test/files/pos/bug304.scala new file mode 100644 index 0000000000..76da44157d --- /dev/null +++ b/test/files/pos/bug304.scala @@ -0,0 +1,5 @@ +object O { + def f1 = -1; + def f2 = 0-1; + def f3 = -f1; +} diff --git a/test/files/pos/viewtest1.scala b/test/files/pos/viewtest1.scala new file mode 100755 index 0000000000..e908e2acb9 --- /dev/null +++ b/test/files/pos/viewtest1.scala @@ -0,0 +1,41 @@ +package test; + +trait Ordered[a] { + def < (x: a): boolean; +} + +object O { + def view (x: String): Ordered[String] = new Ordered[String] { + def < (y: String) = x.compareTo(y) < 0; + } +} + +object Empty extends Tree[All]; +case class Node[+c <% Ordered[c]](elem: c, l: Tree[c], r: Tree[c]) extends Tree[c]; + +trait Tree[+a <% Ordered[a]] { + def insert[b >: a <% Ordered[b]](x: b): Tree[b] = this match { + case Empty => new Node(x, Empty, Empty) + case Node(elem, l, r) => + if (x == elem) this + else if (x < elem) Node(elem, l insert x, r) + else Node(elem, l, r insert x); + } + def elements: List[a] = this match { + case Empty => List() + case Node(elem, l, r) => + l.elements ::: List(elem) ::: r.elements + } +} + +object Test { + import O.view; + + def main(args: Array[String]) = { + var t: Tree[String] = Empty; + for (val s <- args) { + t = t insert s + } + System.out.println(t.elements) + } +} diff --git a/test/files/pos/viewtest2.scala b/test/files/pos/viewtest2.scala new file mode 100755 index 0000000000..aa8d33ed6c --- /dev/null +++ b/test/files/pos/viewtest2.scala @@ -0,0 +1,77 @@ +package test; + +object O { + def view (x: String): Ordered[String] = new Ordered[String] { + def compareTo [b >: String <% Ordered[b]](y: b): int = y match { + case y1: String => x compareTo y1; + case _ => -(y compareTo x) + } + } + def view (x: char): Ordered[char] = new Ordered[char] { + def compareTo [b >: char <% Ordered[b]](y: b): int = y match { + case y1: char => x - y1; + case _ => -(y compareTo x) + } + } + def view[a <% Ordered[a]](x: List[a]): Ordered[List[a]] = + new Ordered[List[a]] { + def compareTo [b >: List[a] <% Ordered[b]](y: b): int = y match { + case y1: List[a] => compareLists(x, y1); + case _ => -(y compareTo x) + } + private def compareLists(xs: List[a], ys: List[a]): int = { + if (xs.isEmpty && ys.isEmpty) 0 + else if (xs.isEmpty) -1 + else if (ys.isEmpty) 1 + else { + val s = xs.head compareTo ys.head; + if (s != 0) s + else compareLists(xs.tail, ys.tail) + } + } + } +} + +trait Tree[+a <% Ordered[a]] { + def insert[b >: a <% Ordered[b]](x: b): Tree[b]; + def elements: List[a] +} + +object Empty extends Tree[All] { + def insert[b >: All <% Ordered[b]](x: b): Tree[b] = new Node(x, Empty, Empty); + def elements: List[All] = List(); +} + +class Node[+a <% Ordered[a]](elem: a, l: Tree[a], r: Tree[a]) extends Tree[a] { + def insert[b >: a <% Ordered[b]](x: b): Tree[b] = + if (x == elem) this + else if (x < elem) new Node(elem, l insert x, r) + else new Node(elem, l, r insert x); + def elements: List[a] = + l.elements ::: List(elem) ::: r.elements +} + +object Test { + import O.view; + + private def toCharList(s: String): List[Char] = + if (s.length() == 0) List() + else s.charAt(0) :: toCharList(s.substring(1)); + + def main(args: Array[String]) = { + { + var t: Tree[String] = Empty; + for (val s <- args) { + t = t insert s + } + System.out.println(t.elements) + } + { + var t: Tree[List[char]] = Empty; + for (val s <- args) { + t = t insert toCharList(s) + } + System.out.println(t.elements) + } + } +} |