diff options
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/jvm/interpreter.check | 20 | ||||
-rw-r--r-- | test/files/jvm/interpreter.scala | 9 | ||||
-rw-r--r-- | test/files/neg/t2130.check | 4 | ||||
-rwxr-xr-x | test/files/neg/t2130.scala | 6 | ||||
-rw-r--r-- | test/files/neg/t2336.check | 4 | ||||
-rwxr-xr-x | test/files/neg/t2336.scala | 7 | ||||
-rwxr-xr-x | test/files/pos/lexical.scala | 9 | ||||
-rwxr-xr-x | test/files/pos/packageobjs.scala | 8 | ||||
-rw-r--r-- | test/files/pos/strings.scala | 4 | ||||
-rw-r--r-- | test/files/pos/t2023.scala | 16 | ||||
-rwxr-xr-x | test/files/pos/t2060.scala | 44 | ||||
-rwxr-xr-x | test/files/pos/t2425.scala | 15 | ||||
-rwxr-xr-x | test/files/run/t2127.scala | 32 | ||||
-rw-r--r-- | test/files/run/viewtest.check | 18 | ||||
-rwxr-xr-x | test/files/run/viewtest.scala | 46 |
15 files changed, 240 insertions, 2 deletions
diff --git a/test/files/jvm/interpreter.check b/test/files/jvm/interpreter.check index 07c41b6a1f..27f8be2f57 100644 --- a/test/files/jvm/interpreter.check +++ b/test/files/jvm/interpreter.check @@ -159,6 +159,22 @@ scala> two: Int = 2 scala> scala> scala> +scala> xs: Array[_] = Array(1, 2) + +scala> res2: Int = 2 + +scala> res3: Any = 1 + +scala> res4: Array[_] = Array(2) + +scala> res5: Array[java.lang.String] = Array(abc, abc) + +scala> res6: scala.collection.mutable.GenericArray[_] = GenericArray(1, 2) + +scala> res7: Array[(_$1, _$1)] forSome { type _$1 } = Array((1,1), (2,2)) + +scala> +scala> scala> scala> <console>:1: error: '=' expected but '=>' found. def x => y => z @@ -171,7 +187,7 @@ scala> <console>:1: error: expected start of definition scala> scala> scala> -scala> | | | | res2: scala.xml.Elem = +scala> | | | | res8: scala.xml.Elem = <a> <b d="dd" c="c"></b></a> @@ -181,7 +197,7 @@ scala> | | | | scala> scala> scala> -scala> | | | res3: java.lang.String = +scala> | | | res9: java.lang.String = hello there diff --git a/test/files/jvm/interpreter.scala b/test/files/jvm/interpreter.scala index 21c88734e0..a079af8fe2 100644 --- a/test/files/jvm/interpreter.scala +++ b/test/files/jvm/interpreter.scala @@ -92,6 +92,15 @@ val x20 = 1 val two = one + x5 +// handling generic wildcard arrays (#2386) +// It's put here because type feedback is an important part of it. +val xs: Array[_] = Array(1, 2) +xs.size +xs.head +xs filter (_ == 2) +xs map (_ => "abc") +xs map (x => x) +xs map (x => (x, x)) // interior syntax errors should *not* go into multi-line input mode. // both of the following should abort immediately: diff --git a/test/files/neg/t2130.check b/test/files/neg/t2130.check new file mode 100644 index 0000000000..6d6902b121 --- /dev/null +++ b/test/files/neg/t2130.check @@ -0,0 +1,4 @@ +t2130.scala:4: error: implementation restriction: package object foo cannot contain case class X + case class X() + ^ +one error found diff --git a/test/files/neg/t2130.scala b/test/files/neg/t2130.scala new file mode 100755 index 0000000000..012698fd2a --- /dev/null +++ b/test/files/neg/t2130.scala @@ -0,0 +1,6 @@ +// for now we disallow case class in package objects +package object foo { + + case class X() + +} diff --git a/test/files/neg/t2336.check b/test/files/neg/t2336.check new file mode 100644 index 0000000000..983717469c --- /dev/null +++ b/test/files/neg/t2336.check @@ -0,0 +1,4 @@ +t2336.scala:6: error: type Foo[Int] is not a stable prefix + new Foo[Int]#Bar(0) + ^ +one error found diff --git a/test/files/neg/t2336.scala b/test/files/neg/t2336.scala new file mode 100755 index 0000000000..4cea02b721 --- /dev/null +++ b/test/files/neg/t2336.scala @@ -0,0 +1,7 @@ +// we get now: t2336.scala:5: error: type Foo[Int] is not a stable prefix +class Foo[A] { + class Bar[B >: A](x: B) extends Foo[B] +} +object bug { + new Foo[Int]#Bar(0) +} diff --git a/test/files/pos/lexical.scala b/test/files/pos/lexical.scala new file mode 100755 index 0000000000..034b84bf0f --- /dev/null +++ b/test/files/pos/lexical.scala @@ -0,0 +1,9 @@ +// #2081 +class RichInt(n: Int) { + def days = 1000*60*60*24*n +} + +object Test extends Application { + implicit def RichInt(n: Int): RichInt = new RichInt(n) + println(10.days) +} diff --git a/test/files/pos/packageobjs.scala b/test/files/pos/packageobjs.scala new file mode 100755 index 0000000000..ccab133716 --- /dev/null +++ b/test/files/pos/packageobjs.scala @@ -0,0 +1,8 @@ +package object overloading { + def bar(f: (Int) => Unit): Unit = () + def bar(f: (Int, Int) => Unit): Unit = () +} + +class PackageObjectOverloadingTest { + overloading.bar( (i: Int) => () ) // doesn't compile. +} diff --git a/test/files/pos/strings.scala b/test/files/pos/strings.scala index 3bf40e3dda..9fe8cfd94b 100644 --- a/test/files/pos/strings.scala +++ b/test/files/pos/strings.scala @@ -4,3 +4,7 @@ object test { def f() = "hello".concat("world"); } +// #1000 +object A { + println("""This a "raw" string ending with a "double quote"""") +} diff --git a/test/files/pos/t2023.scala b/test/files/pos/t2023.scala new file mode 100644 index 0000000000..21c6fc96a6 --- /dev/null +++ b/test/files/pos/t2023.scala @@ -0,0 +1,16 @@ +trait C[A] + +object C { + implicit def ipl[A](implicit from: A => Ordered[A]): C[A] = null +} + +object P { + def foo[A](i: A, j: A)(implicit c: C[A]): Unit = () +} + +class ImplicitChainTest { + def testTrivial: Unit = { + P.foo('0', '9') + P.foo('0', '9') + } +} diff --git a/test/files/pos/t2060.scala b/test/files/pos/t2060.scala new file mode 100755 index 0000000000..2c701150e4 --- /dev/null +++ b/test/files/pos/t2060.scala @@ -0,0 +1,44 @@ +/* The problem here is that we cannot insert an implicit to + * add a polymorphic method which is then instantiated to the + * right type. When searching for the implicit in the `fails to compile + * line': + * + * val failure = 1.0 + new Op[Int] + * + * we reduce the problem to finding a function from Double to + * {+: _ >: Op[Int] <: Any}, that is, a method which takes + * an argument which is an Op[Int] or a supertype thereof. + * Class Rich is not a subtype of this structural record, because + * polymorphic method instantiation is not contained in subtyping. + * That is: The method type [I](op : Op[I]): Op[I] is not a subtype + * of (Op[Int]): Op[Int]. + * At present it is unclear whether this problem can be solved. + */ +object Test { + class Op[I]; + class IntOp extends Op[Int]; + + class Rich(x : Double) { + def + (op : IntOp): IntOp = op; + def + [I](op : Op[I]): Op[I] = op; + def plus [I](op : Op[I]): Op[I] = op; + } + + implicit def iToRich(x : Double) = + new Rich(x); + + // fails to compile + val x = 1.0 + new Op[Int] + + // works as expected -- + // problem isn't in adding new "+" + val a = 1.0 + new IntOp; + + // works as expected -- + // problem isn't in binding type variable I + val b = 1.0 plus new Op[Int]; + + // works as expected -- + // problem isn't in using Rich.+[I](op : Op[I]) + val c = iToRich(1.0) + new Op[Int]; +} diff --git a/test/files/pos/t2425.scala b/test/files/pos/t2425.scala new file mode 100755 index 0000000000..403f1a18d7 --- /dev/null +++ b/test/files/pos/t2425.scala @@ -0,0 +1,15 @@ +trait B +class D extends B +object Test extends Application { + def foo[T](bar: T) = { + bar match { + case _: Array[Array[_]] => println("array 2d") + case _: Array[_] => println("array 1d") + case _ => println("something else") + } + } + foo(Array.fill(10)(2)) + foo(Array.fill(10, 10)(2)) + foo(Array.fill(10, 10, 10)(2)) + foo(List(1, 2, 3)) +} diff --git a/test/files/run/t2127.scala b/test/files/run/t2127.scala new file mode 100755 index 0000000000..869d8a38d6 --- /dev/null +++ b/test/files/run/t2127.scala @@ -0,0 +1,32 @@ +// Seems to be fixed in trunk + +// As discussed here: http://www.nabble.com/Companion-object-constructor-visibility-td24342096.html + +//Simplified example: + + class Test private (val value : Int) + + abstract class Bar(val ctor : (Int) => Test) + + object Test extends Bar(new Test(_)) { //<--- ILLEGAL ACCESS + def main(args: Array[String]){} + } + +//however the following is legal: +/* + class Foo private (val value : Int) + + abstract class Bar{ + + var ctor : (Int) => Foo + + } + + object Foo extends Bar{ + + ctor = new Foo(_) //<--- Legal access + + } + +The constructor invocation of Bar is done within the scope of object Foo's constructor, and therefor the private constructor of Foo should be visible and accessible. +*/ diff --git a/test/files/run/viewtest.check b/test/files/run/viewtest.check new file mode 100644 index 0000000000..ded3ac0e92 --- /dev/null +++ b/test/files/run/viewtest.check @@ -0,0 +1,18 @@ +SeqViewZ((x,0)) +ys defined +mapping 1 +2 +mapping 1 +mapping 2 +mapping 3 +SeqViewMS(3, 4) +mapping 3 +4 +mapping 1 +mapping 2 +mapping 3 +SeqViewM(2, 3, 4) +mapping 1 +mapping 2 +mapping 3 +List(2, 3, 4) diff --git a/test/files/run/viewtest.scala b/test/files/run/viewtest.scala new file mode 100755 index 0000000000..0f00536c1c --- /dev/null +++ b/test/files/run/viewtest.scala @@ -0,0 +1,46 @@ +import collection._ +object Test extends Application { + + val xs: SeqView[(String, Int), Seq[_]] = List("x").view.zip(Stream.from(0)) + println(xs) + + val ys = List(1, 2, 3).view map { x => println("mapping "+x); x + 1 } + println("ys defined") + println(ys.head) + println(ys.tail) + println(ys(2)) + println(ys) + println(ys.force) + + val zs = Array(1, 2, 3).view + val as: VectorView[Int, Array[Int]] = zs map (_ + 1) + val bs: Array[Int] = as.force + val cs = zs.reverse + cs(0) += 1 + assert(cs.force.deep == Array(4, 2, 1).deep) + assert(zs(2) == 4) + assert(bs.deep == Array(2, 3, 4).deep) +} + +/* crash confirmed. +2.8 regression: CCE when zipping list projection with stream +Reported by: szeiger Owned by: odersky +Priority: normal Component: Standard Library +Keywords: collections, zip Cc: +Fixed in version: +Description + +Welcome to Scala version 2.8.0.r18784-b20090925021043 (Java HotSpot(TM) Client VM, Java 1.6.0_11). +Type in expressions to have them evaluated. +Type :help for more information. + +scala> List("x").view.zip(Stream.from(0))List("x").view.zip(Stream.from(0)) +java.lang.ClassCastException: scala.collection.generic.IterableViewTemplate$$anon$8 cannot be cast to scala.collection.generic.SequenceView + at .<init>(<console>:5) + at .<clinit>(<console>) + at RequestResult$.<init>(<console>:4) + at RequestResult$.<clinit>(<console>) + at RequestResult$result(<console>) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.Nat... +*/ |