From 6054eda86b92e133796b6a08de84307a9e0f8f40 Mon Sep 17 00:00:00 2001 From: Christopher Fujino Date: Tue, 28 Dec 2021 18:19:16 -0800 Subject: [PATCH] fix lateinitialization error in devicelab-runner (#94957) --- dev/devicelab/bin/tasks/module_test_ios.dart | 4 +++- dev/devicelab/lib/framework/ios.dart | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/dev/devicelab/bin/tasks/module_test_ios.dart b/dev/devicelab/bin/tasks/module_test_ios.dart index afd5201e12..cffc8a7c65 100644 --- a/dev/devicelab/bin/tasks/module_test_ios.dart +++ b/dev/devicelab/bin/tasks/module_test_ios.dart @@ -18,7 +18,9 @@ import 'package:path/path.dart' as path; /// adding Flutter to an existing iOS app. Future main() async { await task(() async { - late String simulatorDeviceId; + // this variable cannot be `late`, as we reference it in the `finally` block + // which may execute before this field has been initialized + String? simulatorDeviceId; section('Create Flutter module project'); final Directory tempDir = Directory.systemTemp.createTempSync('flutter_module_test.'); diff --git a/dev/devicelab/lib/framework/ios.dart b/dev/devicelab/lib/framework/ios.dart index 487820c27f..e0691fcfa3 100644 --- a/dev/devicelab/lib/framework/ios.dart +++ b/dev/devicelab/lib/framework/ios.dart @@ -116,14 +116,14 @@ Future testWithNewIOSSimulator( } /// Shuts down and deletes simulator with deviceId. -Future removeIOSimulator(String deviceId) async { +Future removeIOSimulator(String? deviceId) async { if (deviceId != null && deviceId != '') { await eval( 'xcrun', [ 'simctl', 'shutdown', - deviceId + deviceId, ], canFail: true, workingDirectory: flutterDirectory.path, @@ -133,7 +133,8 @@ Future removeIOSimulator(String deviceId) async { [ 'simctl', 'delete', - deviceId], + deviceId, + ], canFail: true, workingDirectory: flutterDirectory.path, );