scala / collection-strawman

Implementation of the new Scala 2.13 Collections
Apache License 2.0
200 stars 72 forks source link

Override knownSize in empty collections #496

Closed julienrf closed 6 years ago

julienrf commented 6 years ago

Fixes scala/collection-strawman#437

lrytz commented 6 years ago

If I understand correctly, those empty collections would inherit def knownSize: Int = -1. It seems that this should not lead to correctness bugs, i.e., indexOfSlice is using knownSize wrongly - no?

julienrf commented 6 years ago

That’s a good point, actually indexOfSlice’s implementation is missing a test that makes it incorrect in the case the receiver is empty (but knownSize is -1). I’ve just added it.