-
Notifications
You must be signed in to change notification settings - Fork 233
Closed
Description
An empty Tokens
should throw on head
and last
and apply
but does not when it avoids a bounds check on the underlying array. (last
started throwing on 2.13.12.; head
was also improved, so the override should use super.head
.)
@data class Tokens private (
private val tokens: Array[Token],
private val start: Int,
private val end: Int
) extends immutable.IndexedSeq[Token] with IndexedSeqOptimized[Token] {
def apply(idx: Int): Token = tokens(start + idx)
def length: Int = end - start
override def slice(from: Int, until: Int): Tokens = {
val lo = start + from.max(0).min(length)
val hi = lo.max(start + until.min(length))
Tokens(tokens, lo, hi)
}
/* Both head and headOption need to be implemented here due to
* binary incompatibility caused by
* https://github.com/scala/scala/commit/b20dd00b11f06c14c823d277cdfb58043a2586fc
*/
override def head: Token = apply(0)
Noticed at scala/community-build#1680 (comment)
Metadata
Metadata
Assignees
Labels
No labels