Skip to content

Commit 42ac402

Browse files
authored
Add updated to SeqViewOps (#19798)
Fixes #19660
2 parents d35eba0 + 3287f06 commit 42ac402

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

scala2-library-cc/src/scala/collection/SeqView.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ trait SeqViewOps[+A, +CC[_], +C] extends Any with IterableOps[A, CC, C] {
3030
def length: Int
3131
def apply(x: Int): A
3232
def appended[B >: A](elem: B): CC[B]^{this}
33+
def updated[B >: A](index: Int, elem: B): CC[B]^{this}
3334
def prepended[B >: A](elem: B): CC[B]^{this}
3435
def reverse: C^{this}
3536
def sorted[B >: A](implicit ord: Ordering[B]): C^{this}
@@ -44,6 +45,16 @@ trait SeqView[+A] extends SeqViewOps[A, View, View[A]] with View[A] {
4445

4546
override def map[B](f: A => B): SeqView[B]^{this, f} = new SeqView.Map(this, f)
4647
override def appended[B >: A](elem: B): SeqView[B]^{this} = new SeqView.Appended(this, elem)
48+
49+
// Copied from SeqOps. This is needed due to the change of class hierarchy in stdlib.
50+
// See #19660.
51+
override def updated[B >: A](index: Int, elem: B): View[B]^{this} = {
52+
if(index < 0) throw new IndexOutOfBoundsException(index.toString)
53+
val k = knownSize
54+
if(k >= 0 && index >= k) throw new IndexOutOfBoundsException(index.toString)
55+
iterableFactory.from(new View.Updated(this, index, elem))
56+
}
57+
4758
override def prepended[B >: A](elem: B): SeqView[B]^{this} = new SeqView.Prepended(elem, this)
4859
override def reverse: SeqView[A]^{this} = new SeqView.Reverse(this)
4960
override def take(n: Int): SeqView[A]^{this} = new SeqView.Take(this, n)

0 commit comments

Comments
 (0)