From aae55894be5b58e7f3aa38cf692c638255aebb2b Mon Sep 17 00:00:00 2001 From: hellohuanlin <41930132+hellohuanlin@users.noreply.github.com> Date: Sat, 16 Nov 2024 09:26:20 -0800 Subject: [PATCH] [ios]fix unused variable clang tidy warning (flutter/engine#56637) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Spot another clang-tidy linter failure from: https://github.com/flutter/engine/pull/56631 In release mode, if we remove NSAssert, then weakFlutterEngine is not used at all. This should have been an XCTAssert rather than NSAssert in the first place. ``` ❌ Failures for clang-tidy on /Volumes/Work/s/w/ir/cache/builder/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm: /Volumes/Work/s/w/ir/cache/builder/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm:239:5: error: Value stored to 'weakFlutterEngine' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors] 239 | weakFlutterEngine = flutterEngine; | ^ ~~~~~~~~~~~~~ /Volumes/Work/s/w/ir/cache/builder/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm:239:5: note: Value stored to 'weakFlutterEngine' is never read 239 | weakFlutterEngine = flutterEngine; | ^ ~~~~~~~~~~~~~ Suppressed 9240 warnings (9111 in non-user code, 129 NOLINT). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. ``` *List which issues are fixed by this PR. You must list at least one issue.* https://github.com/flutter/flutter/issues/157837 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../ios/framework/Source/FlutterTextInputPluginTest.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm index ec39029c67..be00f6e1e6 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm @@ -237,7 +237,7 @@ FLUTTER_ASSERT_ARC @autoreleasepool { FlutterEngine* flutterEngine = OCMClassMock([FlutterEngine class]); weakFlutterEngine = flutterEngine; - NSAssert(weakFlutterEngine, @"flutter engine must not be nil"); + XCTAssertNotNil(weakFlutterEngine, @"flutter engine must not be nil"); FlutterTextInputPlugin* flutterTextInputPlugin = [[FlutterTextInputPlugin alloc] initWithDelegate:(id)flutterEngine]; weakFlutterTextInputPlugin = flutterTextInputPlugin; @@ -254,8 +254,8 @@ FLUTTER_ASSERT_ARC currentView = flutterTextInputPlugin.activeView; } - NSAssert(!weakFlutterEngine, @"flutter engine must be nil"); - NSAssert(currentView, @"current view must not be nil"); + XCTAssertNil(weakFlutterEngine, @"flutter engine must be nil"); + XCTAssertNotNil(currentView, @"current view must not be nil"); XCTAssertNil(weakFlutterTextInputPlugin); // Verify that the view can no longer access the deallocated engine/text input plugin