diff --git a/CHANGELOG.md b/CHANGELOG.md index 3de6f7bc..33f414f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ -#### 3.2.0 +#### 3.2.0-dev + * Explicitly disallow a `nullable` type argument for `Optional`. * Expose `TreeIterator` for iterating `TreeSet` instead of using `BidirectionalIterator`. * Require Dart 2.17 diff --git a/analysis_options.yaml b/analysis_options.yaml index deee90df..2dc1dc35 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,11 +1,6 @@ # https://dart.dev/guides/language/analysis-options include: package:lints/recommended.yaml -analyzer: - errors: - # TODO(kevmoo): see https://github.com/dart-lang/linter/issues/3844 - null_check_on_nullable_type_parameter: ignore - linter: rules: - always_declare_return_types diff --git a/lib/src/collection/bimap.dart b/lib/src/collection/bimap.dart index cc41456d..6dd45a3e 100644 --- a/lib/src/collection/bimap.dart +++ b/lib/src/collection/bimap.dart @@ -151,7 +151,7 @@ class HashBiMap implements BiMap { @override void updateAll(V Function(K key, V value) update) { for (final key in keys) { - _add(key, update(key, _map[key]!), true); + _add(key, update(key, _map[key] as V), true); } } diff --git a/lib/src/collection/lru_map.dart b/lib/src/collection/lru_map.dart index fabbcf72..b0a927eb 100644 --- a/lib/src/collection/lru_map.dart +++ b/lib/src/collection/lru_map.dart @@ -290,7 +290,7 @@ class LinkedLruHashMap implements LruMap { V update(K key, V Function(V value) update, {V Function()? ifAbsent}) { V newValue; if (containsKey(key)) { - newValue = update(this[key]!); + newValue = update(this[key] as V); } else { if (ifAbsent == null) { throw ArgumentError.value(key, 'key', 'Key not in map'); diff --git a/lib/src/collection/treeset.dart b/lib/src/collection/treeset.dart index c42cc704..743f9e0c 100644 --- a/lib/src/collection/treeset.dart +++ b/lib/src/collection/treeset.dart @@ -899,7 +899,9 @@ class TreeIterator {this.reversed = false, this.inclusive = true, V? anchorObject}) : _anchorObject = anchorObject, _modCountGuard = tree._modCount { - if (_anchorObject == null || tree.isEmpty) { + final anchor = _anchorObject; + + if (anchor == null || tree.isEmpty) { // If the anchor is far left or right, we're just a normal iterator. _state = reversed ? _right : _left; _moveNext = reversed ? _movePreviousNormal : _moveNextNormal; @@ -911,28 +913,26 @@ class TreeIterator // Else we've got an anchor we have to worry about initializing from. // This isn't known till the caller actually performs a previous/next. _moveNext = () { - _current = tree._searchNearest(_anchorObject, + _current = tree._searchNearest(anchor, option: reversed ? TreeSearch.LESS_THAN : TreeSearch.GREATER_THAN); _moveNext = reversed ? _movePreviousNormal : _moveNextNormal; _movePrevious = reversed ? _moveNextNormal : _movePreviousNormal; if (_current == null) { _state = reversed ? _left : _right; - } else if (tree.comparator(_current!.object, _anchorObject!) == 0 && - !inclusive) { + } else if (tree.comparator(_current!.object, anchor) == 0 && !inclusive) { _moveNext(); } return _state == _walk; }; _movePrevious = () { - _current = tree._searchNearest(_anchorObject, + _current = tree._searchNearest(anchor, option: reversed ? TreeSearch.GREATER_THAN : TreeSearch.LESS_THAN); _moveNext = reversed ? _movePreviousNormal : _moveNextNormal; _movePrevious = reversed ? _moveNextNormal : _movePreviousNormal; if (_current == null) { _state = reversed ? _right : _left; - } else if (tree.comparator(_current!.object, _anchorObject!) == 0 && - !inclusive) { + } else if (tree.comparator(_current!.object, anchor) == 0 && !inclusive) { _movePrevious(); } return _state == _walk; diff --git a/lib/src/core/optional.dart b/lib/src/core/optional.dart index ed8ec894..42ab9e51 100644 --- a/lib/src/core/optional.dart +++ b/lib/src/core/optional.dart @@ -23,7 +23,7 @@ import 'dart:collection'; /// With the introduction of non-null by default in Dart SDK 2.12, developers /// should avoid adding more uses of this type. Existing users should migrate /// away from the `Optional` type to types marked nullable: `T?`. -class Optional extends IterableBase { +class Optional extends IterableBase { /// Constructs an empty Optional. const Optional.absent() : _value = null; diff --git a/lib/src/iterables/generating_iterable.dart b/lib/src/iterables/generating_iterable.dart index 8facce80..9796b1b9 100644 --- a/lib/src/iterables/generating_iterable.dart +++ b/lib/src/iterables/generating_iterable.dart @@ -67,9 +67,10 @@ class _GeneratingIterator implements Iterator { @override bool moveNext() { - if (object == null) return false; + final obj = object; + if (obj == null) return false; if (started) { - object = next(object!); + object = next(obj); } else { started = true; }