[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "google-objc-*" clang analyzer warning in macOS and iOS #29764

Merged
merged 3 commits into from
Nov 18, 2021

Conversation

jmagman
Copy link
Member
@jmagman jmagman commented Nov 16, 2021

Run clang-tidy on host_debug and ios_debug for google-objc-* analyzer checks.

Part of flutter/flutter#93279 and flutter/flutter#91857

$ ../buildtools/mac-x64/clang/bin/clang-tidy --dump-config
Checks:          'clang-diagnostic-*,clang-analyzer-*,google-*,-google-objc-global-variable-declaration,-google-objc-avoid-throwing-exception'
WarningsAsErrors: 'clang-analyzer-osx.*,google-objc-*'

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

@@ -173,7 +173,7 @@ - (NSUInteger)hash {
}
@end

NSObject const* FlutterMethodNotImplemented = [NSObject new];
NSObject const* FlutterMethodNotImplemented = [[NSObject alloc] init];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-objc-avoid-nsobject-new

@@ -6,7 +6,7 @@

#include "gtest/gtest.h"

void checkEncodeDecode(id value, NSData* expectedEncoding) {
static void CheckEncodeDecode(id value, NSData* expectedEncoding) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-objc-function-naming

@@ -21,18 +21,6 @@
// TODO(amirh): once GL support is in evaluate if we can merge this with FlutterView.
@implementation FlutterOverlayView

- (instancetype)initWithFrame:(CGRect)frame {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-objc-avoid-throwing-exception
I ignored this check in .clang-tidy since there are a few more tricky ones to fix. However, these throwing implementations should be removed, they are already marked as NS_UNAVAILABLE in the header.

- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NS_UNAVAILABLE won't catch all usage of these selectors. How about refactoring this to NSAssert calls?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What situations does it not cover? Are you worried about the selector being send to it?

@interface Foo : NSObject
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithStuff NS_DESIGNATED_INITIALIZER;
- (void)doStuff;
@end
@interface Bar : Foo
@end

Screen Shot 2021-11-16 at 1 52 04 PM

Screen Shot 2021-11-16 at 1 50 10 PM

Screen Shot 2021-11-16 at 1 49 45 PM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, exactly. Xib's for example will execute initWithCoder:. It uses the objc runtime to execute the selector so NS_UNAVAILABLE won't effect it.

Copy link
Member Author
@jmagman jmagman Nov 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, for UIView subclasses and similar, good catch.

@@ -39,12 +39,6 @@ @implementation FlutterPlatformPlugin {
fml::WeakPtr<FlutterEngine> _engine;
}

- (instancetype)init {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

@@ -20,13 +20,6 @@ @implementation FlutterRestorationPlugin {
BOOL _restorationEnabled;
}

- (instancetype)init {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

@@ -21,24 +21,6 @@ @implementation FlutterView {
id<FlutterViewEngineDelegate> _delegate;
}

- (instancetype)init {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;

@@ -15,12 +15,6 @@ @implementation FlutterTextureRegistrar {
NSMutableDictionary<NSNumber*, id<FlutterMacOSExternalTexture>>* _textures;
}

- (instancetype)init {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- (nullable instancetype)init NS_UNAVAILABLE;

@@ -27,4 +27,4 @@ id CreateMockViewController(NSString* pasteboardString) {
}
}

}
} // namespace flutter::testing
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-readability-namespace-comments wasn't turned on, but I spotted it, may as well fix it.

Copy link
Member
@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo throws should be changed to NSAsserts.

@@ -21,18 +21,6 @@
// TODO(amirh): once GL support is in evaluate if we can merge this with FlutterView.
@implementation FlutterOverlayView

- (instancetype)initWithFrame:(CGRect)frame {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NS_UNAVAILABLE won't catch all usage of these selectors. How about refactoring this to NSAssert calls?

@jmagman jmagman added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Nov 17, 2021
@fluttergithubbot fluttergithubbot merged commit 598ac02 into flutter:main Nov 18, 2021
@jmagman jmagman deleted the clang-google-objc branch November 18, 2021 00:50
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes platform-ios platform-macos waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
3 participants