Skip to content

Commit

Permalink
Avoid passing a nullable value to Future<nn-type>.value (#3567)
Browse files Browse the repository at this point in the history
This is cleanup work required to start enforcing this with static analysis, as per dart-lang/sdk#53253.

Real quick this issue is that this code is unsafe:

```dart
void f(Completer<int> c, int? i) {
  Future<int>.value(i); // Ouch!
  c.complete(i);        // Ouch!
}
```

- Thanks for your contribution! Please replace this text with a description of what this PR is changing or adding and why, list any relevant issues, and review the contribution guidelines below.

---

<details>
  <summary>Contribution guidelines:</summary><br>

- See our [contributor guide](https://github.com/dart-lang/.github/blob/main/CONTRIBUTING.md) for general expectations for PRs.
- Larger or significant changes should be discussed in an issue before creating a PR.
- Contributions to our repos should follow the [Dart style guide](https://dart.dev/guides/language/effective-dart) and use `dart format`.
- Most changes should add an entry to the changelog and may need to [rev the pubspec package version](https://github.com/dart-lang/sdk/wiki/External-Package-Maintenance#making-a-change).
- Changes to packages require [corresponding tests](https://github.com/dart-lang/.github/blob/main/CONTRIBUTING.md#Testing).

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.
</details>
  • Loading branch information
srawlins authored Sep 1, 2023
1 parent d47a527 commit 627de7d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions build_test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.2.1-dev

- Avoid passing a nullable value to `Future.value`.

## 2.2.0

- Forward logs from `testBuilder` to `printOnFailure` by default.
Expand Down
2 changes: 1 addition & 1 deletion build_test/lib/src/written_asset_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class WrittenAssetReader extends MultiPackageAssetReader {
if (!source.assets.containsKey(id)) {
throw AssetNotFoundException(id);
}
return Future.value(source.assets[id]);
return Future.value(source.assets[id]!);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion build_test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: build_test
description: Utilities for writing unit tests of Builders.
version: 2.2.0
version: 2.2.1-dev
repository: https://github.com/dart-lang/build/tree/master/build_test

environment:
Expand Down

0 comments on commit 627de7d

Please sign in to comment.