Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

immutable.BitSet unsafely fails on addition of negative numbers #8622

Open
scabug opened this issue May 26, 2014 · 4 comments
Open

immutable.BitSet unsafely fails on addition of negative numbers #8622

scabug opened this issue May 26, 2014 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 26, 2014

This throws an exception, which is not at all expected or expectable when looking at the Set interface.

val s: collection.immutable.Set = collection.immutable.BitSet(1,2,3)
s + -1

The + method should be fixed to avoid violating LSP.

@scabug
Copy link
Author

scabug commented May 26, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8622?orig=1
Reporter: @Ichoran
Affected Versions: 2.11.0

@scabug
Copy link
Author

scabug commented Sep 30, 2014

@Ichoran said:
This is not limited to just +; everything without a CanBuildFrom is affected also. In fact, it's a fundamental weakness of the design where a BitSet cannot actually live up to the requirements of Set. Not sure that there's a good fix for this since we can't restrict to positive integers.

Instead, maybe we should let BitSet hold negative integers. There's no reason it can't.

@scabug
Copy link
Author

scabug commented Aug 10, 2016

@SethTisue said:
good ol' BitSet

@scabug
Copy link
Author

scabug commented Nov 9, 2016

@szeiger said:
This also affects methods with CanBuildFrom:

scala> val s: scala.collection.immutable.Set[Int] = scala.collection.immutable.BitSet(1,2,3).map(- _)
java.lang.IllegalArgumentException: requirement failed
  at scala.Predef$.require(Predef.scala:207)
  at scala.collection.mutable.BitSet.add(BitSet.scala:83)
  at scala.collection.mutable.BitSet.$plus$eq(BitSet.scala:102)
  at scala.collection.immutable.BitSet$$anon$1.$plus$eq(BitSet.scala:74)
  at scala.collection.immutable.BitSet$$anon$1.$plus$eq(BitSet.scala:72)
  at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
  at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
  at scala.collection.BitSetLike$class.foreach(BitSetLike.scala:128)
  at scala.collection.immutable.BitSet.foreach(BitSet.scala:28)
  at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
  at scala.collection.AbstractSet.scala$collection$SetLike$$super$map(Set.scala:47)
  at scala.collection.SetLike$class.map(SetLike.scala:92)
  at scala.collection.AbstractSet.map(Set.scala:47)
  ... 33 elided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants