Unverified Commit a4254c78 authored by Paul Berry's avatar Paul Berry Committed by GitHub

Ignore dead_code hints for weak-only null checks. (#63007)

* Ignore dead_code hints for weak-only null checks.

When https://github.com/dart-lang/sdk/issues/41985 is fixed, the
analyzer will begin detecting dead code due to "unnecessary" null
checks.  Since we want to retain null checks in Flutter even when they
appear unnecessary (in order to preserve runtime behavior in weak
mode), we need to suppress these dead code hints.

* Add comments explaining why we're ignoring dead_code hints
parent d7883e3f
...@@ -66,8 +66,11 @@ abstract class AssetBundle { ...@@ -66,8 +66,11 @@ abstract class AssetBundle {
/// implementation.) /// implementation.)
Future<String> loadString(String key, { bool cache = true }) async { Future<String> loadString(String key, { bool cache = true }) async {
final ByteData data = await load(key); final ByteData data = await load(key);
// Note: data has a non-nullable type, but might be null when running with
// weak checking, so we need to null check it anyway (and ignore the warning
// that the null-handling logic is dead code).
if (data == null) if (data == null)
throw FlutterError('Unable to load asset: $key'); throw FlutterError('Unable to load asset: $key'); // ignore: dead_code
if (data.lengthInBytes < 10 * 1024) { if (data.lengthInBytes < 10 * 1024) {
// 10KB takes about 3ms to parse on a Pixel 2 XL. // 10KB takes about 3ms to parse on a Pixel 2 XL.
// See: https://github.com/dart-lang/sdk/issues/31954 // See: https://github.com/dart-lang/sdk/issues/31954
......
...@@ -88,7 +88,7 @@ class BasicMessageChannel<T> { ...@@ -88,7 +88,7 @@ class BasicMessageChannel<T> {
/// ///
/// This is intended for testing. Messages intercepted in this manner are not /// This is intended for testing. Messages intercepted in this manner are not
/// sent to platform plugins. /// sent to platform plugins.
void setMockMessageHandler(Future<T> Function(T message) handler) { void setMockMessageHandler(Future<T> Function(T message)? handler) {
if (handler == null) { if (handler == null) {
binaryMessenger.setMockMessageHandler(name, null); binaryMessenger.setMockMessageHandler(name, null);
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment