From c854cc7fcc9d0f889c6235c1534133cff7360e7f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 17 Mar 2014 18:44:39 +0100 Subject: More tests --- tests/pos/t1000.scala | 8 ++++ tests/pos/t1001.scala | 115 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/pos/t1006.scala | 15 +++++++ tests/pos/t1014.scala | 16 +++++++ tests/pos/t1027.scala | 18 ++++++++ tests/pos/t1034.scala | 6 +++ tests/pos/t1035.scala | 32 ++++++++++++++ tests/pos/t1048.scala | 14 ++++++ tests/pos/t1049.scala | 7 +++ tests/pos/t1050.scala | 10 +++++ tests/pos/t1053.scala | 6 +++ tests/pos/t1056.scala | 5 +++ tests/pos/t1070.scala | 4 ++ tests/pos/t1075.scala | 17 ++++++++ tests/pos/t1085.scala | 9 ++++ tests/pos/t1090.scala | 16 +++++++ tests/pos/t1107a.scala | 10 +++++ tests/pos/t1119.scala | 10 +++++ tests/pos/t1131.scala | 4 ++ tests/pos/t1133.scala | 32 ++++++++++++++ tests/pos/t1136.scala | 8 ++++ tests/pos/t1146.scala | 6 +++ tests/pos/t1147.scala | 6 +++ tests/pos/t115.scala | 9 ++++ tests/pos/t1159.scala | 13 ++++++ tests/pos/t116.scala | 6 +++ tests/pos/t1164.scala | 29 +++++++++++++ tests/pos/t1168.scala | 16 +++++++ tests/pos/t1185.scala | 15 +++++++ tests/pos/t119.scala | 7 +++ tests/pos/t1203a.scala | 13 ++++++ tests/pos/t121.scala | 3 ++ tests/pos/t1210a.scala | 15 +++++++ tests/pos/t122.scala | 4 ++ tests/pos/t1226.scala | 8 ++++ tests/pos/t1237.scala | 14 ++++++ tests/pos/t124.scala | 5 +++ tests/pos/t1260.scala | 18 ++++++++ 38 files changed, 549 insertions(+) create mode 100644 tests/pos/t1000.scala create mode 100644 tests/pos/t1001.scala create mode 100644 tests/pos/t1006.scala create mode 100644 tests/pos/t1014.scala create mode 100644 tests/pos/t1027.scala create mode 100644 tests/pos/t1034.scala create mode 100644 tests/pos/t1035.scala create mode 100644 tests/pos/t1048.scala create mode 100644 tests/pos/t1049.scala create mode 100644 tests/pos/t1050.scala create mode 100644 tests/pos/t1053.scala create mode 100644 tests/pos/t1056.scala create mode 100644 tests/pos/t1070.scala create mode 100644 tests/pos/t1075.scala create mode 100644 tests/pos/t1085.scala create mode 100644 tests/pos/t1090.scala create mode 100644 tests/pos/t1107a.scala create mode 100644 tests/pos/t1119.scala create mode 100644 tests/pos/t1131.scala create mode 100644 tests/pos/t1133.scala create mode 100644 tests/pos/t1136.scala create mode 100644 tests/pos/t1146.scala create mode 100644 tests/pos/t1147.scala create mode 100644 tests/pos/t115.scala create mode 100644 tests/pos/t1159.scala create mode 100644 tests/pos/t116.scala create mode 100644 tests/pos/t1164.scala create mode 100644 tests/pos/t1168.scala create mode 100644 tests/pos/t1185.scala create mode 100644 tests/pos/t119.scala create mode 100644 tests/pos/t1203a.scala create mode 100644 tests/pos/t121.scala create mode 100644 tests/pos/t1210a.scala create mode 100644 tests/pos/t122.scala create mode 100644 tests/pos/t1226.scala create mode 100644 tests/pos/t1237.scala create mode 100644 tests/pos/t124.scala create mode 100644 tests/pos/t1260.scala (limited to 'tests/pos') diff --git a/tests/pos/t1000.scala b/tests/pos/t1000.scala new file mode 100644 index 000000000..613af76b9 --- /dev/null +++ b/tests/pos/t1000.scala @@ -0,0 +1,8 @@ +object A { + println("""This a "raw" string ending with a "double quote"""") +} + +object Test extends App { + val xs = Array(1, 2, 3) + Console.println(xs.filter(_ >= 0).length) +} diff --git a/tests/pos/t1001.scala b/tests/pos/t1001.scala new file mode 100644 index 000000000..7a06bfa0e --- /dev/null +++ b/tests/pos/t1001.scala @@ -0,0 +1,115 @@ +// was t1001.scala +class Foo; + +object Overload{ + val foo = classOf[Foo].getConstructors()(0) + foo.getDeclaringClass +} + +// was t1001.scala + +// I suspect the stack overflow is occurring when the compiler is determining the types for the following line at the end of the file:- +// val data = List(N26,N25) + +abstract class A +{ + // commenting out the following line (only) leads to successful compilation + protected val data: List[A] +} + +trait B[T <: B[T]] extends A { self: T => } + +abstract class C extends A +{ + // commenting out the following line (only) leads to successful compilation + protected val data: List[C] +} + +abstract class D extends C with B[D] {} + +abstract class Ee extends C with B[Ee] +{ +} + + +object N1 extends D +{ + val data = Nil +} + +object N2 extends D +{ + val data = Nil +} + +object N5 extends D +{ + val data = List(N1) +} + +object N6 extends D +{ + val data = List(N1) +} + +object N8 extends D +{ + val data = List(N1) +} + +object N10 extends D +{ + val data = Nil +} + +object N13 extends D +{ + val data = List(N2) +} + +object N14 extends D +{ + val data = List(N5,N10,N8) +} + +object N15 extends D +{ + val data = List(N14) +} + +object N16 extends D +{ + val data = List(N13,N6,N15) +} + +object N17 extends D +{ + val data = List(N16) +} + +object N21 extends D +{ + val data = List(N16) +} + +object N22 extends D +{ + val data = List(N17) +} + +object N25 extends D +{ + val data = List(N22) +} + +object N26 extends Ee +{ + val data = List(N21,N17) +} + +// Commenting out the following object (only) leads to successful compilation +object N31 extends Ee +{ + // If we use List[C](N26,N25), we achieve successful compilation + val data = List[C](N26,N25) +} diff --git a/tests/pos/t1006.scala b/tests/pos/t1006.scala new file mode 100644 index 000000000..2163b2b74 --- /dev/null +++ b/tests/pos/t1006.scala @@ -0,0 +1,15 @@ +object Test extends App { + +def test(): Unit = { + + abstract class A[T] { + def myVal: T + } + + class B[T1](value: T1) extends A[T1] { + def myVal: T1 = value + } + + Console.println(new B[Int](23).myVal) +} +} diff --git a/tests/pos/t1014.scala b/tests/pos/t1014.scala new file mode 100644 index 000000000..6fb7f7ba4 --- /dev/null +++ b/tests/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/tests/pos/t1027.scala b/tests/pos/t1027.scala new file mode 100644 index 000000000..02ba9a8a3 --- /dev/null +++ b/tests/pos/t1027.scala @@ -0,0 +1,18 @@ +object T1027 extends App { + trait Comparable[T <: Comparable[T]] { this: T => + def < (that: T): Boolean + def <=(that: T): Boolean = this < that || this == that + def > (that: T): Boolean = that < this + def >=(that: T): Boolean = that <= this + } + class A(val x: String) extends Comparable[A]{ + def < (that: A) = this.x < that.x + } + val a = new A("a") + val b = new A("b") + println(a < b) + println(a > b) + println(a <= b) + println(a >= b) + println("Comparable traits : " + (new A("x") > new A("y")).toString) + } diff --git a/tests/pos/t1034.scala b/tests/pos/t1034.scala new file mode 100644 index 000000000..9d966334a --- /dev/null +++ b/tests/pos/t1034.scala @@ -0,0 +1,6 @@ +object Terminal { + def apply[a] : a => Unit = { a => () } + val i0 = Terminal.apply[Int] + val i1 = (Terminal)[Int] + val i2 = Terminal[Int] +} diff --git a/tests/pos/t1035.scala b/tests/pos/t1035.scala new file mode 100644 index 000000000..ef81cb0d9 --- /dev/null +++ b/tests/pos/t1035.scala @@ -0,0 +1,32 @@ +//A fatal error or Scala compiler +// Scala compiler version 2.7.1-final -- (c) 2002-2011 LAMP/EPFL +// Carlos Loria cloria@artinsoft.com +// 7/10/2008 + +class A { + var name:String = _ + def getName() = name + def this(name:String, age:Int) = {this(); this.name = name} + +} + +class B(name:String) extends A(name,0){ +} + +class D { + + object A { + def unapply(p:A) = Some(p.getName) + } + + object B { + def unapply(p:B) = Some(p.getName) + } + def foo(p:Any) = p match { + case B(n) => println("B") + case A(n) => println("A") + + + } + +} diff --git a/tests/pos/t1048.scala b/tests/pos/t1048.scala new file mode 100644 index 000000000..b8694b38e --- /dev/null +++ b/tests/pos/t1048.scala @@ -0,0 +1,14 @@ +trait T[U] { + def x: T[_ <: U] +} + +object T { + def unapply[U](t: T[U]): Option[T[_ <: U]] = Some(t.x) +} + +object Test { + def f[W](t: T[W]) = t match { + case T(T(_)) => () + } +} + diff --git a/tests/pos/t1049.scala b/tests/pos/t1049.scala new file mode 100644 index 000000000..61d99f946 --- /dev/null +++ b/tests/pos/t1049.scala @@ -0,0 +1,7 @@ +package t1049 + +abstract class Test { + type T <: A + class A { self: T => } + class B extends A { self: T => } +} diff --git a/tests/pos/t1050.scala b/tests/pos/t1050.scala new file mode 100644 index 000000000..d34b0cff1 --- /dev/null +++ b/tests/pos/t1050.scala @@ -0,0 +1,10 @@ +package t1050 + +abstract class A { + type T <: scala.AnyRef + class A { this: T => + def b = 3 + def c = b + b + } +} diff --git a/tests/pos/t1053.scala b/tests/pos/t1053.scala new file mode 100644 index 000000000..1d4dfb637 --- /dev/null +++ b/tests/pos/t1053.scala @@ -0,0 +1,6 @@ +trait T[A] { trait U { type W = A; val x = 3 } } + +object Test { + val x : ({ type V = T[this.type] })#V = null + val y = new x.U { } +} diff --git a/tests/pos/t1056.scala b/tests/pos/t1056.scala new file mode 100644 index 000000000..68f1ff273 --- /dev/null +++ b/tests/pos/t1056.scala @@ -0,0 +1,5 @@ +object Test { + type T = PartialFunction[String,String] + def g(h: T) = () + g({case s: String => s}) +} diff --git a/tests/pos/t1070.scala b/tests/pos/t1070.scala new file mode 100644 index 000000000..1622043a8 --- /dev/null +++ b/tests/pos/t1070.scala @@ -0,0 +1,4 @@ +import scala.beans.BeanProperty; +trait beanpropertytrait { + @BeanProperty var myVariable: Long = -1l; +} diff --git a/tests/pos/t1075.scala b/tests/pos/t1075.scala new file mode 100644 index 000000000..5f72957da --- /dev/null +++ b/tests/pos/t1075.scala @@ -0,0 +1,17 @@ +class Directory(var dir_ : String) +{ + if (!dir_.startsWith("/")) { + throw new RuntimeException("Invalid directory") + } + dir_ = dir_.replaceAll("/{2,}", "/") + + def this(serialized : Array[Byte]) = { + this(new String(serialized, "UTF-8")) + } + + def dir = dir_ +} + +object Test extends Directory("/bab/dkkd//dkkdkd//kdkdk") with App { + println(dir) +} diff --git a/tests/pos/t1085.scala b/tests/pos/t1085.scala new file mode 100644 index 000000000..c59e657cb --- /dev/null +++ b/tests/pos/t1085.scala @@ -0,0 +1,9 @@ +trait Functor[a] { + type MyType[a] +} + +object Test { + def listFunctor[a]: Functor[a]{type MyType[x]=List[x]} = new Functor[a] { + type MyType[t]=List[t] + } +} diff --git a/tests/pos/t1090.scala b/tests/pos/t1090.scala new file mode 100644 index 000000000..a9bce90b0 --- /dev/null +++ b/tests/pos/t1090.scala @@ -0,0 +1,16 @@ +object Test { + trait Manager { + type Node; + def iterator : Iterator[Node] + } + trait Core { + type Node; + trait NodeImpl + trait Manager extends Test.Manager { + type Node = Core.this.Node + } + def f(manager : Manager) = manager.iterator.foreach{ + case node : NodeImpl => + } + } +} diff --git a/tests/pos/t1107a.scala b/tests/pos/t1107a.scala new file mode 100644 index 000000000..0bf40bb4c --- /dev/null +++ b/tests/pos/t1107a.scala @@ -0,0 +1,10 @@ +object F { + type AnyClass = Class[_] + def tryf[T](ignore: List[AnyClass])(f: => T): Any = { + try { + f + } catch { + case e if ignore == null || ignore.isEmpty => {false} + } + } +} diff --git a/tests/pos/t1119.scala b/tests/pos/t1119.scala new file mode 100644 index 000000000..8b36877c4 --- /dev/null +++ b/tests/pos/t1119.scala @@ -0,0 +1,10 @@ +trait B +{ + type T >: this.type <: B + + + // compile-time check: have we achieved our objective? + def test: T = this +} + + diff --git a/tests/pos/t1131.scala b/tests/pos/t1131.scala new file mode 100644 index 000000000..1b2a90457 --- /dev/null +++ b/tests/pos/t1131.scala @@ -0,0 +1,4 @@ +trait A { self: Any { def p: Any } => + def f(b: => Unit): Unit = {} + f { p } +} diff --git a/tests/pos/t1133.scala b/tests/pos/t1133.scala new file mode 100644 index 000000000..562b528ea --- /dev/null +++ b/tests/pos/t1133.scala @@ -0,0 +1,32 @@ +object Match +{ + def main(args: Array[String]) = { + args(0) match { + case Extractor1(Extractor2(Extractor3("dog", "dog", "dog"), x2, x3), b, c, Extractor3("b", "b", f), e) => println(e) + case Extractor3(Extractor2(Extractor1("a", "aa", "aaa", "aa", "a"), Extractor2("a", "aa", "aaa"), e), y, z) => println(e) + case Extractor2(Extractor3("a", "a", x), Extractor3("b", "b", y), Extractor3("c", "c", z)) => println(z) + case _ => println("fail") + } + } + + object Extractor1 { + def unapply(x: Any) = x match { + case x: String => Some(x, x+x, x+x+x, x+x, x) + case _ => None + } + } + + object Extractor2 { + def unapply(x: Any) = x match { + case x: String => Some(x, x+x, x+x+x) + case _ => None + } + } + + object Extractor3 { + def unapply(x: Any) = x match { + case x: String => Some(x, x, x) + case _ => None + } + } +} diff --git a/tests/pos/t1136.scala b/tests/pos/t1136.scala new file mode 100644 index 000000000..92d603e69 --- /dev/null +++ b/tests/pos/t1136.scala @@ -0,0 +1,8 @@ +object test { + def foo(s: Int*): Unit = { + s.toList match { + case t: List[Int] => foo(t: _*) + //case _ => // unreachable code + } + } +} diff --git a/tests/pos/t1146.scala b/tests/pos/t1146.scala new file mode 100644 index 000000000..7e5adc4f4 --- /dev/null +++ b/tests/pos/t1146.scala @@ -0,0 +1,6 @@ +class Code { + val _ = () => { + val arr = Array[String]() + null + } +} diff --git a/tests/pos/t1147.scala b/tests/pos/t1147.scala new file mode 100644 index 000000000..ff2e8bc52 --- /dev/null +++ b/tests/pos/t1147.scala @@ -0,0 +1,6 @@ +class App(arg: String) { + @deprecated("..") def this() = { + this("foo") + } +} + diff --git a/tests/pos/t115.scala b/tests/pos/t115.scala new file mode 100644 index 000000000..0e6a63c16 --- /dev/null +++ b/tests/pos/t115.scala @@ -0,0 +1,9 @@ +class S[A](f: A => A, x: A) { + Console.println(f(x)); +} +class T[B](f: B => B, y: B) extends S((x: B) => f(x), y) { +} +object Test extends App { + new T[Int](x => x * 2, 1); + val f = new S((x: Int) => x, 1); +} diff --git a/tests/pos/t1159.scala b/tests/pos/t1159.scala new file mode 100644 index 000000000..7e09418b2 --- /dev/null +++ b/tests/pos/t1159.scala @@ -0,0 +1,13 @@ +object test17 { + def main(args : Array[String]) = { + val value = + if (false) + new java.lang.Float(0) + else if (false) + new java.lang.Long(0) + else + new java.lang.Integer(0) + + println(value) + } +} diff --git a/tests/pos/t116.scala b/tests/pos/t116.scala new file mode 100644 index 000000000..1e31b71bf --- /dev/null +++ b/tests/pos/t116.scala @@ -0,0 +1,6 @@ +class C { + def this(x: Int) = { + this(); + class D extends C; + } +} diff --git a/tests/pos/t1164.scala b/tests/pos/t1164.scala new file mode 100644 index 000000000..ab58c1d6b --- /dev/null +++ b/tests/pos/t1164.scala @@ -0,0 +1,29 @@ + + +object test { + + class Foo[a](val arg : a) + + object Foo { + def apply [a](arg : a, right :a) = new Foo[a](arg) + def unapply [a](m : Foo[a]) = Some (m.arg) + } + + def matchAndGetArgFromFoo[a]( e:Foo[a]):a = {e match { case Foo(x) => x }} + + + // Try the same thing as above but use function as argument to Bar + // constructor + + type FunIntToA [a] = (Int) => a + class Bar[a] (var f: FunIntToA[a]) + + object Bar { + def apply[a](f: FunIntToA[a]) = new Bar[a](f) + def unapply[a](m: Bar[a]) = Some (m.f) + } + + def matchAndGetFunFromBar[a](b:Bar[a]) : FunIntToA[a] = { b match { case Bar(x) => x}} + + +} diff --git a/tests/pos/t1168.scala b/tests/pos/t1168.scala new file mode 100644 index 000000000..75638e792 --- /dev/null +++ b/tests/pos/t1168.scala @@ -0,0 +1,16 @@ +object Test extends App { + + trait SpecialException {} + + try { + throw new Exception + } catch { + case e : SpecialException => { + println("matched SpecialException: "+e) + assume(e.isInstanceOf[SpecialException]) + } + case e : Exception => { + assume(e.isInstanceOf[Exception]) + } + } +} diff --git a/tests/pos/t1185.scala b/tests/pos/t1185.scala new file mode 100644 index 000000000..fa863d158 --- /dev/null +++ b/tests/pos/t1185.scala @@ -0,0 +1,15 @@ +class Test { + private[this] var member = 0; + def foo() = { + (() => member=1)() + } + def look=member +} + +object Main{ + def main(args : Array[String]): Unit = { + val fff=new Test() + fff.foo() + assert(1==fff.look) + } +} diff --git a/tests/pos/t119.scala b/tests/pos/t119.scala new file mode 100644 index 000000000..44a156675 --- /dev/null +++ b/tests/pos/t119.scala @@ -0,0 +1,7 @@ +class K[E] { + case class A(v: E) {} +} + +class K2 extends K[Int] { + val A(v) = A(42) +} diff --git a/tests/pos/t1203a.scala b/tests/pos/t1203a.scala new file mode 100644 index 000000000..cf5ab9fba --- /dev/null +++ b/tests/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/tests/pos/t121.scala b/tests/pos/t121.scala new file mode 100644 index 000000000..78ddc41ee --- /dev/null +++ b/tests/pos/t121.scala @@ -0,0 +1,3 @@ +class Bug121_B(b: Array[Byte]) { + def get(x: Int): Byte = return b(x); +} diff --git a/tests/pos/t1210a.scala b/tests/pos/t1210a.scala new file mode 100644 index 000000000..b3492f96e --- /dev/null +++ b/tests/pos/t1210a.scala @@ -0,0 +1,15 @@ +// both styles of abstraction should behave the same +// related to 1210 because that bug broke the OO version below +trait OO { + abstract class Test { self => + type T + + val v: Test {type T = self.T} = self.v.v + } +} + +trait FP { + abstract class Test[T] { + val v: Test[T] = v.v + } +} diff --git a/tests/pos/t122.scala b/tests/pos/t122.scala new file mode 100644 index 000000000..630e24ce4 --- /dev/null +++ b/tests/pos/t122.scala @@ -0,0 +1,4 @@ +class L { + val List(v:Int, 2) = List(2, v:Int) + val (a:Int, b:Int) = (1, a) +} diff --git a/tests/pos/t1226.scala b/tests/pos/t1226.scala new file mode 100644 index 000000000..0af21cbb6 --- /dev/null +++ b/tests/pos/t1226.scala @@ -0,0 +1,8 @@ +package graphs; + +abstract class Graph (private[graphs] val mappings : Any){ +} + +class Nodes (mappings : Any) extends Graph(mappings) { + mappings.toString; +} diff --git a/tests/pos/t1237.scala b/tests/pos/t1237.scala new file mode 100644 index 000000000..31ba2966a --- /dev/null +++ b/tests/pos/t1237.scala @@ -0,0 +1,14 @@ +class HelloWorld { + def main(args: Array[String]): Unit = { + + object TypeBool; + + trait Fct { + def g(x : Int) = TypeBool // breaks. + + // def g(x : Int) = 3 // fine. + } + + () + } +} diff --git a/tests/pos/t124.scala b/tests/pos/t124.scala new file mode 100644 index 000000000..9aed6786f --- /dev/null +++ b/tests/pos/t124.scala @@ -0,0 +1,5 @@ +class N{ + val F: Any => Any = (x:Any) => F(x); + val f:(Any => Any) = (x:Any) => f(x); + val g: Any => Any = (x:Any) => g(x); +} diff --git a/tests/pos/t1260.scala b/tests/pos/t1260.scala new file mode 100644 index 000000000..02f9e7e6b --- /dev/null +++ b/tests/pos/t1260.scala @@ -0,0 +1,18 @@ +case class Foo(a: String, b: String) + +object Bar { + def unapply(s: String): Option[Long] = + try { Some(s.toLong) } catch { case _ => None } +} + +object Test { + def main(args: Array[String]): Unit = { + val f = Foo("1", "2") + f match { + case Foo(Bar(1), Bar(2)) => 1 + case Foo(Bar(i), Bar(j)) if i >= 0 => 2 + case _ => 3 + } + } +} + -- cgit v1.2.3