Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1940eaf

Browse files
Restore collection.Map --, Fixes scala/bug#10957
1 parent d9ecc84 commit 1940eaf

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

src/library/scala/collection/Map.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,19 @@ trait MapOps[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _], +C]
288288
override def mkString(sep: String): String = super.mkString(sep)
289289
override def mkString: String = super.mkString
290290

291-
@deprecated("Consider requiring an immutable Map or fall back to Map.concat", "2.13.0")
292-
def + [V1 >: V](kv: (K, V1)): CC[K, V1] = mapFactory.from(new View.Appended(toIterable, kv))
291+
@deprecated("Consider requiring an immutable Map or fall back to Map.concat.", "2.13.0")
292+
def + [V1 >: V](kv: (K, V1)): CC[K, V1] =
293+
mapFactory.from(new View.Appended(toIterable, kv))
293294

294295
@deprecated("Use ++ with an explicit collection argument instead of + with varargs", "2.13.0")
295-
def + [V1 >: V](elem1: (K, V1), elem2: (K, V1), elems: (K, V1)*): CC[K, V1] = mapFactory.from(new View.Concat(new View.Appended(new View.Appended(toIterable, elem1), elem2), elems))
296+
def + [V1 >: V](elem1: (K, V1), elem2: (K, V1), elems: (K, V1)*): CC[K, V1] =
297+
mapFactory.from(new View.Concat(new View.Appended(new View.Appended(toIterable, elem1), elem2), elems))
298+
299+
@deprecated("Consider requiring an immutable Map.", "2.13.0")
300+
@`inline` def -- (keys: IterableOnce[K]): C = {
301+
lazy val keysSet = keys.toSet
302+
fromSpecificIterable(this.filterKeys(k => !keysSet.contains(k)))
303+
}
296304
}
297305

298306
object MapOps {

src/library/scala/collection/immutable/Map.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ trait MapOps[K, +V, +CC[X, +Y] <: MapOps[X, Y, CC, _], +C <: MapOps[K, V, CC, C]
7676
def removeAll(keys: IterableOnce[K]): C = keys.iterator.foldLeft[C](coll)(_ - _)
7777

7878
/** Alias for `removeAll` */
79-
@`inline` final def -- (keys: IterableOnce[K]): C = removeAll(keys)
79+
@deprecatedOverriding("This method should be final, but is not due to scala/bug#10853", "2.13.0")
80+
/* @`inline` final */ override def -- (keys: IterableOnce[K]): C = removeAll(keys)
8081

8182
/** Creates a new map obtained by updating this map with a given key/value pair.
8283
* @param key the key
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package scala.collection
2+
3+
import org.junit.runner.RunWith
4+
import org.junit.runners.JUnit4
5+
import org.junit.Assert._
6+
import org.junit.Test
7+
8+
@RunWith(classOf[JUnit4])
9+
class MapTest {
10+
@Test def test: Unit = {
11+
val map = collection.Map(
12+
1 -> 1,
13+
2 -> 2,
14+
4 -> 4,
15+
5 -> 5
16+
)
17+
18+
val actual = map -- List(1, 2, 3)
19+
20+
val expected = collection.Map(
21+
4 -> 4,
22+
5 -> 5
23+
)
24+
25+
assertEquals(expected, actual)
26+
}
27+
}

0 commit comments

Comments
 (0)