ObjC selector checking not working sufficiently

Originator:misacek
Number:rdar://49622319 Date Originated:April 4 2019
Status:Open Resolved:
Product:Xcode Product Version:10.2
Classification:UI Reproducible:Always
 
Summary:

In particular cases, selector validity checking isn't working as expected – warning about unimplemented methods.

Specifically, when defining some protocol with required and optional methods:

– required methods which are not implemented by the class are handled by a non-conforming warning
– non-existing methods are handled by `undeclared selector` warning
– an implemented optional method is okay

BUT

– unimplemented optional methods throw no warning at all – they are hypothetically declared (by the protocol), but not actually implemented (as these don't need to be because of optionality), but once one attempts to reference using a @selector(), no warning (f.e. `unimplemented` warning) is given. Calling such selector via `-canPerformSelector:`/`-performSelector` may prevent the issue (but only silently), calling the `-selector` directly throws an error, but using it when binding f.e. via `-addTarget:action:` using a @selector() remains silent, eventually leading to `unrecognized selector sent to instance` runtime error.

See the attached files for details.

Strict selector checking is set ON.

Expected Results:
Better selector checking in optional case.

Actual Results:
Uncaught cases which may result in `unrecognized selector sent to instance` crashes.

Version/Build:
Xcode 10.2

Configuration:
macOS Mojave 10.14.5 beta @ MacBook Air 2012
macOS Mojave 10.14.4 @ Mac mini 2012

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!