- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
2.8 RC7 RichString bug?
Mon, 2010-07-05, 15:59
According to the documentation of drop in traversable:
The return is a collection with the first n ones, or else the empty collection. This holds true for example for list:
But when I tried it out on a string:
scala> "a".drop(1)
res3: String =
scala> "a".drop(1).drop(1)
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1937)
at scala.collection.immutable.StringOps.slice(StringOps.scala:40)
at scala.collection.immutable.StringOps.slice(StringOps.scala:31)
at scala.collection.IndexedSeqOptimized$class.drop(IndexedSeqOptimized.scala:145)
at scala.collection.immutable.StringOps.drop(StringOps.scala:31)
at .<init>(<console>:6)
at .<clinit>(<console>)
at RequestResult$.<init>(<console>:9)
at RequestResult$.<clinit>(<console>)
at RequestResult$scala_repl_result(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcc...
:( , this is a bug right?
Cheers.
Selects all elements except first n ones.
Note: might return different results for different runs, unless the underlying collection type is ordered.
- n
the number of elements to drop from this collection.
- returns
a collection consisting of all elements of this collection except the first
n
ones, or else the empty collection, if this collection has less thann
elements.
definition classes: TraversableLike
The return is a collection with the first n ones, or else the empty collection. This holds true for example for list:
scala> List(1).drop(1)
res0: List[Int] = List()
scala> List(1).drop(1).drop(1)
res1: List[Int] = List()
scala> List(1).drop(1).drop(1).drop(1)
res2: List[Int] = List()
But when I tried it out on a string:
scala> "a".drop(1)
res3: String =
scala> "a".drop(1).drop(1)
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1937)
at scala.collection.immutable.StringOps.slice(StringOps.scala:40)
at scala.collection.immutable.StringOps.slice(StringOps.scala:31)
at scala.collection.IndexedSeqOptimized$class.drop(IndexedSeqOptimized.scala:145)
at scala.collection.immutable.StringOps.drop(StringOps.scala:31)
at .<init>(<console>:6)
at .<clinit>(<console>)
at RequestResult$.<init>(<console>:9)
at RequestResult$.<clinit>(<console>)
at RequestResult$scala_repl_result(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcc...
:( , this is a bug right?
Cheers.
Mon, 2010-07-05, 17:17
#2
Re: Re: 2.8 RC7 RichString bug?
On Mon, Jul 05, 2010 at 12:04:57PM -0300, Rodrigo Cano wrote:
> Sorry, it's not RichString, it's StringOps bug.
I fixed it.
Mon, 2010-07-05, 17:27
#3
Re: Re: 2.8 RC7 RichString bug?
And if you happen to look at it and find something... disturbing... be
aware there's another patch right on its heels.
Mon, 2010-07-05, 17:27
#4
Re: Re: 2.8 RC7 RichString bug?
Awsome :D
Tue, 2010-07-06, 08:27
#5
Re: Re: 2.8 RC7 RichString bug?
You should become an exterminator ;)
2010/7/5 Paul Phillips :
> And if you happen to look at it and find something... disturbing... be
> aware there's another patch right on its heels.
>
> --
> Paul Phillips | We must respect the other fellow's religion, but only
> Moral Alien | in the sense and to the extent that we respect his
> Empiricist | theory that his wife is beautiful and his children smart.
> all hip pupils! | -- H. L. Mencken
>
Wed, 2010-07-14, 01:27
#6
Re: Re: 2.8 RC7 RichString bug?
On Mon, Jul 5, 2010 at 6:01 PM, Paul Phillips wrote:
> On Mon, Jul 05, 2010 at 12:04:57PM -0300, Rodrigo Cano wrote:
>> Sorry, it's not RichString, it's StringOps bug.
>
> I fixed it.
>
> http://lampsvn.epfl.ch/trac/scala/changeset/22489
>
Actually, that's the wrong way. slice is defined to be forgiving for
bounds out of range. So the added tests are redundant and confusing
because they hide this design decision. What's wrong is
StringOps.slice, which needs to correct out of range bounds.
Cheers
Wed, 2010-07-14, 02:37
#7
Re: Re: 2.8 RC7 RichString bug?
On Wed, Jul 14, 2010 at 02:18:17AM +0200, martin odersky wrote:
> Actually, that's the wrong way. slice is defined to be forgiving for
> bounds out of range. So the added tests are redundant and confusing
> because they hide this design decision. What's wrong is
> StringOps.slice, which needs to correct out of range bounds.
Shoot, I wrote that specifically thinking that slice is unforgiving.
That's quite a handy thing to know, maybe I'll use it more. I'll
correct it.
On Mon, Jul 5, 2010 at 11:59 AM, Rodrigo Cano <ioniviil@gmail.com> wrote: