diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ba67719590..dbf56b7fba8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,11 +13,18 @@ #### Other Tools ### Core library changes -* `dart:async` - * Update `Stream.fromIterable` to send a done event after the the error when +#### `dart:async` + +* Update `Stream.fromIterable` to send a done event after the the error when the iterator's `moveNext` throws, and handle if the `current` getter throws. Issue [33431](http://dartbug.com/33431). +#### `dart:core` + +* Added missing methods to `UnmodifiableMapMixin`. Some maps intended to + be unmodifiable incorrectly allowed new methods added in Dart 2 to + succeed. + ## 2.1.0-dev.2.0 ### Tool Changes diff --git a/sdk/lib/collection/maps.dart b/sdk/lib/collection/maps.dart index 795a2e3cc5a..60f66e18cc0 100644 --- a/sdk/lib/collection/maps.dart +++ b/sdk/lib/collection/maps.dart @@ -282,6 +282,11 @@ abstract class _UnmodifiableMapMixin implements Map { throw new UnsupportedError("Cannot modify unmodifiable map"); } + /** This operation is not supported by an unmodifiable map. */ + void addEntries(Iterable> entries) { + throw new UnsupportedError("Cannot modify unmodifiable map"); + } + /** This operation is not supported by an unmodifiable map. */ void clear() { throw new UnsupportedError("Cannot modify unmodifiable map"); @@ -292,10 +297,25 @@ abstract class _UnmodifiableMapMixin implements Map { throw new UnsupportedError("Cannot modify unmodifiable map"); } + /** This operation is not supported by an unmodifiable map. */ + void removeWhere(bool test(K key, V value)) { + throw new UnsupportedError("Cannot modify unmodifiable map"); + } + /** This operation is not supported by an unmodifiable map. */ V putIfAbsent(K key, V ifAbsent()) { throw new UnsupportedError("Cannot modify unmodifiable map"); } + + /** This operation is not supported by an unmodifiable map. */ + V update(K key, V update(V value), {V ifAbsent()}) { + throw new UnsupportedError("Cannot modify unmodifiable map"); + } + + /** This operation is not supported by an unmodifiable map. */ + void updateAll(V update(K key, V value)) { + throw new UnsupportedError("Cannot modify unmodifiable map"); + } } /** @@ -341,7 +361,7 @@ class MapView implements Map { Iterable> get entries => _map.entries; - void addEntries(Iterable entries) { + void addEntries(Iterable> entries) { _map.addEntries(entries); } diff --git a/tests/corelib_2/corelib_2.status b/tests/corelib_2/corelib_2.status index dda114ea207..c4bdc22c427 100644 --- a/tests/corelib_2/corelib_2.status +++ b/tests/corelib_2/corelib_2.status @@ -89,6 +89,7 @@ symbol_test/03: MissingCompileTimeError [ !$strong ] cast_test: SkipByDesign # Uses generic method parameters. iterable_where_type_test: SkipByDesign +map_test: SkipByDesign regress_33166_test: SkipByDesign # Not a Dart 1 test [ $arch == simarmv5te && ($runtime == dart_precompiled || $runtime == vm) ] diff --git a/tests/corelib_2/map_test.dart b/tests/corelib_2/map_test.dart index 275b5e6525d..5c9e9a4833a 100644 --- a/tests/corelib_2/map_test.dart +++ b/tests/corelib_2/map_test.dart @@ -27,6 +27,7 @@ void main() { testMapLiteral(); testNullValue(); testTypes(); + testUnmodifiableMaps(); testWeirdStringKeys(new Map()); testWeirdStringKeys(new Map()); @@ -703,8 +704,7 @@ class Equalizer { int id; Equalizer(this.id); int get hashCode => id; - bool operator ==(Object other) => - other is Equalizer && id == (other as Equalizer).id; + bool operator ==(Object other) => other is Equalizer && id == other.id; } /** @@ -721,7 +721,7 @@ class Vampire { // The double-fang operator falsely claims that a vampire is equal to // any of its sire's generation. bool operator ==(Object other) => - other is Vampire && generation - 1 == (other as Vampire).generation; + other is Vampire && generation - 1 == other.generation; } void testCustomMap(Map typedMap) { @@ -1026,3 +1026,21 @@ void testTypeAnnotations(Map map) { Expect.equals(103, map.remove(0x20000000000000)); testLength(1, map); } + +void testUnmodifiableMaps() { + void checkUnmodifiable(Map map) { + Expect.throws(() => map[0] = 0); + Expect.throws(() => map.addAll({0: 0})); + Expect.throws(() => map.addEntries({0: 0}.entries)); + Expect.throws(() => map.clear()); + Expect.throws(() => map.putIfAbsent(0, () => 0)); + Expect.throws(() => map.remove(0)); + Expect.throws(() => map.removeWhere((k, v) => true)); + Expect.throws(() => map.update(0, (v) => v, ifAbsent: () => 0)); + Expect.throws(() => map.updateAll((k, v) => v)); + } + + checkUnmodifiable(const {1: 1}); + checkUnmodifiable(Map.unmodifiable({1: 1})); + checkUnmodifiable(UnmodifiableMapView({1: 1})); +}