diff options
-rw-r--r-- | src/library/scala/collection/GenIterableLike.scala | 3 | ||||
-rw-r--r-- | src/library/scala/collection/GenTraversableLike.scala | 43 | ||||
-rw-r--r-- | src/library/scala/collection/TraversableLike.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/parallel/ParIterableLike.scala | 22 | ||||
-rw-r--r-- | test/files/neg/t4568.check | 4 | ||||
-rw-r--r-- | test/files/neg/t4568.scala | 13 | ||||
-rw-r--r-- | test/files/neg/t750.check | 15 | ||||
-rw-r--r-- | test/files/neg/t750/AO_1.java | 5 | ||||
-rw-r--r-- | test/files/neg/t750/Test_2.scala | 6 | ||||
-rw-r--r-- | test/files/neg/t750b.check | 15 | ||||
-rw-r--r-- | test/files/neg/t750b/AO.java | 5 | ||||
-rw-r--r-- | test/files/neg/t750b/Test.scala | 6 | ||||
-rw-r--r-- | test/files/pos/gen-traversable-methods.scala | 20 | ||||
-rw-r--r-- | test/pending/neg/t1557.scala | 18 | ||||
-rw-r--r-- | test/pending/presentation/t5708.check | 81 | ||||
-rw-r--r-- | test/pending/presentation/t5708/Test.scala | 5 | ||||
-rw-r--r-- | test/pending/presentation/t5708/src/Completions.scala | 11 | ||||
-rw-r--r-- | test/pending/run/t5695.check | 2 | ||||
-rw-r--r-- | test/pending/run/t5695/part_1.scala | 12 | ||||
-rw-r--r-- | test/pending/run/t5695/part_2.scala | 8 |
20 files changed, 286 insertions, 10 deletions
diff --git a/src/library/scala/collection/GenIterableLike.scala b/src/library/scala/collection/GenIterableLike.scala index 79113ddaa7..290a3b26b5 100644 --- a/src/library/scala/collection/GenIterableLike.scala +++ b/src/library/scala/collection/GenIterableLike.scala @@ -141,7 +141,4 @@ trait GenIterableLike[+A, +Repr] extends Any with GenTraversableLike[A, Repr] { */ def zipAll[B, A1 >: A, That](that: GenIterable[B], thisElem: A1, thatElem: B)(implicit bf: CBF[Repr, (A1, B), That]): That - def isEmpty = iterator.isEmpty - - def head = iterator.next } diff --git a/src/library/scala/collection/GenTraversableLike.scala b/src/library/scala/collection/GenTraversableLike.scala index 903594b69d..df652f99d9 100644 --- a/src/library/scala/collection/GenTraversableLike.scala +++ b/src/library/scala/collection/GenTraversableLike.scala @@ -59,12 +59,24 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with def size: Int + /** Selects the first element of this $coll. + * $orderDependent + * @return the first element of this $coll. + * @throws `NoSuchElementException` if the $coll is empty. + */ def head: A - + + /** Optionally selects the first element. + * $orderDependent + * @return the first element of this $coll if it is nonempty, + * `None` if it is empty. + */ + def headOption: Option[A] + /** Tests whether this $coll can be repeatedly traversed. * @return `true` */ - final def isTraversableAgain = true + def isTraversableAgain: Boolean /** Selects all elements except the first. * $orderDependent @@ -72,11 +84,30 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with * except the first one. * @throws `UnsupportedOperationException` if the $coll is empty. */ - def tail: Repr = { - if (isEmpty) throw new UnsupportedOperationException("empty.tail") - drop(1) - } + def tail: Repr + /** Selects the last element. + * $orderDependent + * @return The last element of this $coll. + * @throws NoSuchElementException If the $coll is empty. + */ + def last: A + + /** Optionally selects the last element. + * $orderDependent + * @return the last element of this $coll$ if it is nonempty, + * `None` if it is empty. + */ + def lastOption: Option[A] + + /** Selects all elements except the last. + * $orderDependent + * @return a $coll consisting of all elements of this $coll + * except the last one. + * @throws `UnsupportedOperationException` if the $coll is empty. + */ + def init: Repr + /** Computes a prefix scan of the elements of the collection. * * Note: The neutral element `z` may be applied more than once. diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index 3ca4bfeee9..3716a318d9 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -84,6 +84,8 @@ trait TraversableLike[+A, +Repr] extends Any */ def repr: Repr = this.asInstanceOf[Repr] + final def isTraversableAgain: Boolean = true + /** The underlying collection seen as an instance of `$Coll`. * By default this is implemented as the current collection object itself, * but this can be overridden. diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala index 014b9b1a42..4cb229fc0f 100644 --- a/src/library/scala/collection/parallel/ParIterableLike.scala +++ b/src/library/scala/collection/parallel/ParIterableLike.scala @@ -178,10 +178,30 @@ self: ParIterableLike[T, Repr, Sequential] => def repr: Repr = this.asInstanceOf[Repr] + final def isTraversableAgain = true + def hasDefiniteSize = true + def isEmpty = size == 0 + def nonEmpty = size != 0 - + + def head = iterator.next + + def headOption = if (nonEmpty) Some(head) else None + + def tail = drop(1) + + def last = { + var lst = head + for (x <- this.seq) lst = x + lst + } + + def lastOption = if (nonEmpty) Some(last) else None + + def init = take(size - 1) + /** Creates a new parallel iterator used to traverse the elements of this parallel collection. * This iterator is more specific than the iterator of the returned by `iterator`, and augmented * with additional accessor and transformer methods. diff --git a/test/files/neg/t4568.check b/test/files/neg/t4568.check new file mode 100644 index 0000000000..f94d699486 --- /dev/null +++ b/test/files/neg/t4568.check @@ -0,0 +1,4 @@ +t4568.scala:8: error: recursive method isSubListOf needs result type + case h :: t => y.contains(h) && (t.isSubListOf(y.drop(y.indexOf(h) + 1))) + ^ +one error found diff --git a/test/files/neg/t4568.scala b/test/files/neg/t4568.scala new file mode 100644 index 0000000000..8067759262 --- /dev/null +++ b/test/files/neg/t4568.scala @@ -0,0 +1,13 @@ +object SubList { + implicit def sublistable[A](x: List[A]) = new SubListable(x) + + class SubListable[A](x: List[A]) { + def isSubListOf(y: List[A]) = { + x match { + case Nil => true + case h :: t => y.contains(h) && (t.isSubListOf(y.drop(y.indexOf(h) + 1))) + } + } + } + +}
\ No newline at end of file diff --git a/test/files/neg/t750.check b/test/files/neg/t750.check new file mode 100644 index 0000000000..c17ca334e6 --- /dev/null +++ b/test/files/neg/t750.check @@ -0,0 +1,15 @@ +Test_2.scala:4: error: type mismatch; + found : Array[Int] + required: Array[? with Object] +Note: Int >: ? with Object, but class Array is invariant in type T. +You may wish to investigate a wildcard type such as `_ >: ? with Object`. (SLS 3.2.10) + AO_1.f(a) + ^ +Test_2.scala:5: error: type mismatch; + found : Array[Int] + required: Array[Int] +Note: Int >: Int, but class Array is invariant in type T. +You may wish to investigate a wildcard type such as `_ >: Int`. (SLS 3.2.10) + AO_1.f[Int](a) + ^ +two errors found diff --git a/test/files/neg/t750/AO_1.java b/test/files/neg/t750/AO_1.java new file mode 100644 index 0000000000..4c7360ec6f --- /dev/null +++ b/test/files/neg/t750/AO_1.java @@ -0,0 +1,5 @@ +public class AO_1 { + public static <T> void f(T[] ar0) { + System.out.println(ar0); + } +}
\ No newline at end of file diff --git a/test/files/neg/t750/Test_2.scala b/test/files/neg/t750/Test_2.scala new file mode 100644 index 0000000000..80977431c5 --- /dev/null +++ b/test/files/neg/t750/Test_2.scala @@ -0,0 +1,6 @@ +// t750 +object Test extends App { + val a = Array(1, 2, 3) + AO_1.f(a) + AO_1.f[Int](a) +} diff --git a/test/files/neg/t750b.check b/test/files/neg/t750b.check new file mode 100644 index 0000000000..72a249191e --- /dev/null +++ b/test/files/neg/t750b.check @@ -0,0 +1,15 @@ +Test.scala:4: error: type mismatch; + found : Array[Int] + required: Array[? with Object] +Note: Int >: ? with Object, but class Array is invariant in type T. +You may wish to investigate a wildcard type such as `_ >: ? with Object`. (SLS 3.2.10) + AO.f(a) + ^ +Test.scala:5: error: type mismatch; + found : Array[Int] + required: Array[Int] +Note: Int >: Int, but class Array is invariant in type T. +You may wish to investigate a wildcard type such as `_ >: Int`. (SLS 3.2.10) + AO.f[Int](a) + ^ +two errors found diff --git a/test/files/neg/t750b/AO.java b/test/files/neg/t750b/AO.java new file mode 100644 index 0000000000..060baf9a3c --- /dev/null +++ b/test/files/neg/t750b/AO.java @@ -0,0 +1,5 @@ +public class AO { + public static <T> void f(T[] ar0) { + System.out.println(ar0); + } +}
\ No newline at end of file diff --git a/test/files/neg/t750b/Test.scala b/test/files/neg/t750b/Test.scala new file mode 100644 index 0000000000..5f792a7be8 --- /dev/null +++ b/test/files/neg/t750b/Test.scala @@ -0,0 +1,6 @@ +// t750 +object Test extends App { + val a = Array(1, 2, 3) + AO.f(a) + AO.f[Int](a) +} diff --git a/test/files/pos/gen-traversable-methods.scala b/test/files/pos/gen-traversable-methods.scala new file mode 100644 index 0000000000..2604a09f11 --- /dev/null +++ b/test/files/pos/gen-traversable-methods.scala @@ -0,0 +1,20 @@ + + + +import collection._ + + + +object Test { + + def main(args: Array[String]) { + val gen: GenTraversable[Int] = List(1, 2, 3) + gen.head + gen.headOption + gen.tail + gen.last + gen.lastOption + gen.init + } + +} diff --git a/test/pending/neg/t1557.scala b/test/pending/neg/t1557.scala new file mode 100644 index 0000000000..ba93b45fad --- /dev/null +++ b/test/pending/neg/t1557.scala @@ -0,0 +1,18 @@ +object Test extends App { + trait A + trait B extends A + + trait C { + trait D { type T >: B <: A } + val y: (D with this.type)#T = new B { } + } + + class D extends C { + trait E + type T = E + def frob(arg : E) : E = arg + frob(y) + } + + new D +}
\ No newline at end of file diff --git a/test/pending/presentation/t5708.check b/test/pending/presentation/t5708.check new file mode 100644 index 0000000000..9d944d6cfc --- /dev/null +++ b/test/pending/presentation/t5708.check @@ -0,0 +1,81 @@ +reload: Completions.scala + +askTypeCompletion at Completions.scala(9,9) +================================================================================ +[response] aksTypeCompletion at (9,9) +retrieved 38 members +[accessible: true] `method !=(x$1: Any)Boolean` +[accessible: true] `method !=(x$1: AnyRef)Boolean` +[accessible: true] `method ##()Int` +[accessible: true] `method +(other: String)String` +[accessible: true] `method ->[B](y: B)(test.Compat.type, B)` +[accessible: true] `method ==(x$1: Any)Boolean` +[accessible: true] `method ==(x$1: AnyRef)Boolean` +[accessible: true] `method asInstanceOf[T0]=> T0` +[accessible: true] `method ensuring(cond: Boolean)test.Compat.type` +[accessible: true] `method ensuring(cond: Boolean, msg: => Any)test.Compat.type` +[accessible: true] `method ensuring(cond: test.Compat.type => Boolean)test.Compat.type` +[accessible: true] `method ensuring(cond: test.Compat.type => Boolean, msg: => Any)test.Compat.type` +[accessible: true] `method eq(x$1: AnyRef)Boolean` +[accessible: true] `method equals(x$1: Any)Boolean` +[accessible: true] `method formatted(fmtstr: String)String` +[accessible: true] `method hashCode()Int` +[accessible: true] `method isInstanceOf[T0]=> Boolean` +[accessible: true] `method ne(x$1: AnyRef)Boolean` +[accessible: true] `method notify()Unit` +[accessible: true] `method notifyAll()Unit` +[accessible: true] `method synchronized[T0](x$1: T0)T0` +[accessible: true] `method toString()String` +[accessible: true] `method wait()Unit` +[accessible: true] `method wait(x$1: Long)Unit` +[accessible: true] `method wait(x$1: Long, x$2: Int)Unit` +[accessible: true] `method x=> test.Compat.type` +[accessible: true] `method →[B](y: B)(test.Compat.type, B)` +[accessible: true] `lazy value fooInt` +[accessible: false] `method clone()Object` +[accessible: false] `method finalize()Unit` +[accessible: true] `value CONST_STRINGString("constant")` +[accessible: false] `value __leftOfArrowtest.Compat.type` +[accessible: false] `value __resultOfEnsuringtest.Compat.type` +[accessible: false] `value selfAny` +================================================================================ + +askTypeCompletion at Completions.scala(10,9) +================================================================================ +[response] aksTypeCompletion at (10,9) +retrieved 38 members +[accessible: true] `method !=(x$1: Any)Boolean` +[accessible: true] `method !=(x$1: AnyRef)Boolean` +[accessible: true] `method ##()Int` +[accessible: true] `method +(other: String)String` +[accessible: true] `method ->[B](y: B)(test.Compat.type, B)` +[accessible: true] `method ==(x$1: Any)Boolean` +[accessible: true] `method ==(x$1: AnyRef)Boolean` +[accessible: true] `method asInstanceOf[T0]=> T0` +[accessible: true] `method ensuring(cond: Boolean)test.Compat.type` +[accessible: true] `method ensuring(cond: Boolean, msg: => Any)test.Compat.type` +[accessible: true] `method ensuring(cond: test.Compat.type => Boolean)test.Compat.type` +[accessible: true] `method ensuring(cond: test.Compat.type => Boolean, msg: => Any)test.Compat.type` +[accessible: true] `method eq(x$1: AnyRef)Boolean` +[accessible: true] `method equals(x$1: Any)Boolean` +[accessible: true] `method formatted(fmtstr: String)String` +[accessible: true] `method hashCode()Int` +[accessible: true] `method isInstanceOf[T0]=> Boolean` +[accessible: true] `method ne(x$1: AnyRef)Boolean` +[accessible: true] `method notify()Unit` +[accessible: true] `method notifyAll()Unit` +[accessible: true] `method synchronized[T0](x$1: T0)T0` +[accessible: true] `method toString()String` +[accessible: true] `method wait()Unit` +[accessible: true] `method wait(x$1: Long)Unit` +[accessible: true] `method wait(x$1: Long, x$2: Int)Unit` +[accessible: true] `method x=> test.Compat.type` +[accessible: true] `method →[B](y: B)(test.Compat.type, B)` +[accessible: true] `lazy value fooInt` +[accessible: false] `method clone()Object` +[accessible: false] `method finalize()Unit` +[accessible: true] `value CONST_STRINGString("constant")` +[accessible: false] `value __leftOfArrowtest.Compat.type` +[accessible: false] `value __resultOfEnsuringtest.Compat.type` +[accessible: false] `value selfAny` +================================================================================ diff --git a/test/pending/presentation/t5708/Test.scala b/test/pending/presentation/t5708/Test.scala new file mode 100644 index 0000000000..96e758d974 --- /dev/null +++ b/test/pending/presentation/t5708/Test.scala @@ -0,0 +1,5 @@ +import scala.tools.nsc.interactive.tests.InteractiveTest + +object Test extends InteractiveTest { + +}
\ No newline at end of file diff --git a/test/pending/presentation/t5708/src/Completions.scala b/test/pending/presentation/t5708/src/Completions.scala new file mode 100644 index 0000000000..cc41492df7 --- /dev/null +++ b/test/pending/presentation/t5708/src/Completions.scala @@ -0,0 +1,11 @@ +package test + +object Compat { + final val CONST_STRING = "constant" + lazy val foo = 4 +} + +class Foo { + Compat./*!*/CONST_STRING // its 'accessible' flag is false + Compat./*!*/foo // its 'accessible' flag is false +} diff --git a/test/pending/run/t5695.check b/test/pending/run/t5695.check new file mode 100644 index 0000000000..d50069ab4f --- /dev/null +++ b/test/pending/run/t5695.check @@ -0,0 +1,2 @@ +.. +.. diff --git a/test/pending/run/t5695/part_1.scala b/test/pending/run/t5695/part_1.scala new file mode 100644 index 0000000000..b8e8f8e52f --- /dev/null +++ b/test/pending/run/t5695/part_1.scala @@ -0,0 +1,12 @@ +import language.experimental.macros +import scala.reflect.makro.Context + +object Defs { + + def mkInt = macro mkIntImpl + def mkIntImpl(c: Context): c.Expr[Any] = { + println(c.enclosingApplication) + c.reify{ 23 } + } + +} diff --git a/test/pending/run/t5695/part_2.scala b/test/pending/run/t5695/part_2.scala new file mode 100644 index 0000000000..d34219437d --- /dev/null +++ b/test/pending/run/t5695/part_2.scala @@ -0,0 +1,8 @@ +import Defs._ + +object Test extends App { + + val i1 = mkInt + val i2 = identity(mkInt) + +} |