Warn when protocol conformer implements requirement with mismatched availability

Consider the following setup, where a protocol has added a new requirement in iOS 15:

protocol MyProtocol {
  func theOldWay()

  @available(iOS 15.0, *)
  func theNewWay()

extension MyProtocol {
  func theOldWay() {}

  @available(iOS 20.0, *)
  func theNewWay() {}

If I want to write a conformance to this protocol, I might do the following:

struct Conformer {}
extension Conformer: MyProtocol {
  func theNewWay() {

Unfortunately, if I haven't paid close attention to all the requirements of MyProtocol, and my deployment target is lower than iOS 15, my conformance may misbehave on older iOS versions, since theOldWay() is using the default definition.

Is there any way to trigger a warning in this circumstance?

If not, I suggest that we start warning in such circumstances (when Conformer has a lower minimum availability than an implemented requirement, and perhaps only in an extension which declares the conformance). The fix it would be to explicitly specify the availability of Conformer.theNewWay(), to force users to consider what would happen on older versions. If the function is intended to be available even before it implements the protocol requirement, then it could be annotated according to the minimum deployment target (or the availability of Conformer itself) to silence the error with no change in behavior.

Thoughts? Is there a better existing solution for this pitfall?

1 Like