Skip to content

Commit

Permalink
Update SeqView.updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Linyxus committed Mar 4, 2024
1 parent 99abbdd commit 9ef2676
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion scala2-library-cc/src/scala/collection/Seq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
* lazy collection this exception may be thrown at a later time or not at
* all (if the end of the collection is never evaluated).
*/
def updated[B >: A](index: Int, elem: B): CC[B] = {
override def updated[B >: A](index: Int, elem: B): CC[B] = {
if(index < 0) throw new IndexOutOfBoundsException(index.toString)
val k = knownSize
if(k >= 0 && index >= k) throw new IndexOutOfBoundsException(index.toString)
Expand Down
17 changes: 7 additions & 10 deletions scala2-library-cc/src/scala/collection/SeqView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ trait SeqViewOps[+A, +CC[_], +C] extends Any with IterableOps[A, CC, C] {
def length: Int
def apply(x: Int): A
def appended[B >: A](elem: B): CC[B]^{this}
def updated[B >: A](index: Int, elem: B): CC[B]^{this}
def prepended[B >: A](elem: B): CC[B]^{this}
def reverse: C^{this}
def sorted[B >: A](implicit ord: Ordering[B]): C^{this}

// Placeholder implementation for that method in SeqOps.
// This is needed due to the change in the class hierarchy in cc stdlib.
// See #19660 and #19819.
def updated[B >: A](index: Int, elem: B): CC[B]^{this} =
assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.")
???

def reverseIterator: Iterator[A]^{this} = reversed.iterator
}

Expand All @@ -46,15 +52,6 @@ trait SeqView[+A] extends SeqViewOps[A, View, View[A]] with View[A] {
override def map[B](f: A => B): SeqView[B]^{this, f} = new SeqView.Map(this, f)
override def appended[B >: A](elem: B): SeqView[B]^{this} = new SeqView.Appended(this, elem)

// Copied from SeqOps. This is needed due to the change of class hierarchy in stdlib.
// See #19660.
override def updated[B >: A](index: Int, elem: B): View[B]^{this} = {
if(index < 0) throw new IndexOutOfBoundsException(index.toString)
val k = knownSize
if(k >= 0 && index >= k) throw new IndexOutOfBoundsException(index.toString)
iterableFactory.from(new View.Updated(this, index, elem))
}

override def prepended[B >: A](elem: B): SeqView[B]^{this} = new SeqView.Prepended(elem, this)
override def reverse: SeqView[A]^{this} = new SeqView.Reverse(this)
override def take(n: Int): SeqView[A]^{this} = new SeqView.Take(this, n)
Expand Down

0 comments on commit 9ef2676

Please sign in to comment.