Commits

Devin Coughlin committed 8eeaeea2740
Sema: Infer availability for unannotated Obj-C protocol requirements when diagnosing conformance There have been several cases in the SDK where an Objective-C class is annotated with availability but a related protocol is missing annotations. If this protocol refers to the class in a requirement than it will be impossible for a Swift type to conform to the protocol. One such example the SFSafariViewControllerDelegate protocol: protocol SFSafariViewControllerDelegate { func safariViewControllerDidFinish(controller: SFSafariViewController) } @available(iOS 9.0, *) class SFSafariViewController { } Suppose the user then has a class that she wants to deploy back to iOS 8.0 and yet still conform to SFSafariViewControllerDelegate so she can use SFSafariViewController on iOS 9.0 and above: @available(iOS 8.0, *) class MyViewController : SFSafariViewControllerDelegate { @available(iOS 9.0, *) func safariViewControllerDidFinish(controller: SFSafariViewController) { } } Here the user faces a catch-22: she must mark her witness for safariViewControllerDidFinish() as @available(iOS 9.0, *) -- otherwise availability checking will complain that SFSafariViewController is not available. But if she does so, the checker will complain that MyViewController does not conform to SFSafariViewControllerDelegate because the protocol requires the witness to always be available. This commit adds a little bit of availability inference to protocol conformance checking to solve this problem. When checking Objective-C protocol conformance, it infers the required availability of protocol requirements by looking at the availabilities of the return and parameter types. This is a very targeted inference: it is only used for protocol conformance for Obj-C protocols and it is limited to where neither the protocol nor the protocol requirement has availability markup. This inference can only ever make more the checker more lenient -- it will never cause programs that previously passed checking to fail it. Swift SVN r30060