Skip to content

Commit

Permalink
Revert PbMap._wrappedMap empty map value (#904)
Browse files Browse the repository at this point in the history
Changing `Map.unmodifiable` to a static `<Never, Never>{}` causes runtime type
errors in `firstWhere` uses, in code like `map.keys.firstWhere(f1, orElse: f2)`.

---

cl/585873554
  • Loading branch information
osa1 authored Nov 29, 2023
1 parent cf43230 commit bb19774
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions protobuf/lib/src/protobuf/pb_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,12 @@ class PbMap<K, V> extends MapBase<K, V> {
/// implementation class.
final Map<K, V> _wrappedMap;

/// The map instance to be used in `PbMap.unmodifiable`.
///
/// We can't use `const {}` as it makes the `_wrappedMap` field polymorphic.
static final _emptyMap = <Never, Never>{};

bool _isReadOnly = false;

PbMap(this.keyFieldType, this.valueFieldType) : _wrappedMap = <K, V>{};

PbMap.unmodifiable(this.keyFieldType, this.valueFieldType)
: _wrappedMap = _emptyMap,
: _wrappedMap = <K, V>{},
_isReadOnly = true;

@override
Expand Down

0 comments on commit bb19774

Please sign in to comment.