From a4254c788f96c915e3be1d1c7f544ccbd0caf5d2 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 11 Aug 2020 06:18:39 -0700 Subject: [PATCH] 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 --- packages/flutter/lib/src/services/asset_bundle.dart | 5 ++++- packages/flutter/lib/src/services/platform_channel.dart | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/services/asset_bundle.dart b/packages/flutter/lib/src/services/asset_bundle.dart index 6c66a6c673..e9550a8b8a 100644 --- a/packages/flutter/lib/src/services/asset_bundle.dart +++ b/packages/flutter/lib/src/services/asset_bundle.dart @@ -66,8 +66,11 @@ abstract class AssetBundle { /// implementation.) Future loadString(String key, { bool cache = true }) async { 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) - throw FlutterError('Unable to load asset: $key'); + throw FlutterError('Unable to load asset: $key'); // ignore: dead_code if (data.lengthInBytes < 10 * 1024) { // 10KB takes about 3ms to parse on a Pixel 2 XL. // See: https://github.com/dart-lang/sdk/issues/31954 diff --git a/packages/flutter/lib/src/services/platform_channel.dart b/packages/flutter/lib/src/services/platform_channel.dart index 2e12e495aa..7d6b0d9eec 100644 --- a/packages/flutter/lib/src/services/platform_channel.dart +++ b/packages/flutter/lib/src/services/platform_channel.dart @@ -88,7 +88,7 @@ class BasicMessageChannel { /// /// This is intended for testing. Messages intercepted in this manner are not /// sent to platform plugins. - void setMockMessageHandler(Future Function(T message) handler) { + void setMockMessageHandler(Future Function(T message)? handler) { if (handler == null) { binaryMessenger.setMockMessageHandler(name, null); } else {