diff options
author | Stephen Compall <scompall@nocandysw.com> | 2014-05-24 17:31:19 -0400 |
---|---|---|
committer | Stephen Compall <scompall@nocandysw.com> | 2014-05-24 17:31:19 -0400 |
commit | 9fc098dd0dcf1825ec55501716b4f2a0a6d197ae (patch) | |
tree | 7ef62fa8a9f0f017db7719c3875bba63fc13f0ed /src/library/scala/collection/immutable/ListSet.scala | |
parent | e948b39ca4df48b2acb0e972a2caf674c643a990 (diff) | |
download | scala-9fc098dd0dcf1825ec55501716b4f2a0a6d197ae.tar.gz scala-9fc098dd0dcf1825ec55501716b4f2a0a6d197ae.tar.bz2 scala-9fc098dd0dcf1825ec55501716b4f2a0a6d197ae.zip |
SI-8346: Rebuild invariant sets in #toSet, avoiding CCE.
SI-3953 caused several types of sets' operations to trivially throw
`ClassCastException` after using inherited covariant #toSet method, by
doing an unchecked cast that is only safe for intrinsically covariant
set data structures like `HashSet`, but totally unsafe for others like
`TreeSet` or `Enumeration.ValueSet`.
This change moves the cast to the leaves of the class hierarchy where
that is safe, and incidentally undeprecates overriding Set#toSet.
Diffstat (limited to 'src/library/scala/collection/immutable/ListSet.scala')
-rw-r--r-- | src/library/scala/collection/immutable/ListSet.scala | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/library/scala/collection/immutable/ListSet.scala b/src/library/scala/collection/immutable/ListSet.scala index 1bb07eb02d..89d1a9640e 100644 --- a/src/library/scala/collection/immutable/ListSet.scala +++ b/src/library/scala/collection/immutable/ListSet.scala @@ -138,6 +138,13 @@ class ListSet[A] extends AbstractSet[A] override def stringPrefix = "ListSet" + /** Returns this $coll as an immutable set. + * + * A new set will not be built; lazy collections will stay lazy. + */ + @deprecatedOverriding("Immutable sets should do nothing on toSet but return themselves cast as a Set.", "2.11.0") + override def toSet[B >: A]: Set[B] = this.asInstanceOf[Set[B]] + /** Represents an entry in the `ListSet`. */ protected class Node(override val head: A) extends ListSet[A] with Serializable { |