[swift-evolution] Making protocol conformance inheritance controllable

Michel Fortin michel.fortin at michelf.ca
Fri Dec 11 15:02:53 CST 2015


Le 11 déc. 2015 à 15:21, Joe Groff <jgroff at apple.com> a écrit :

> It's a good question which behavior ought to be default. The good news is that the distinction is only observable for protocols with covariant requirements—initializers, methods returning Self, or properties of type Self. A more conservative change might be:
> 
> - preserve the current inheritance behavior for protocols without covariant requirements;
> - when a class conforms to a protocol with covariant requirements, it must specify whether the conformance is `static` or  `required`, so that neither behavior is default.

Does it make sense to say the protocol is `required` when it contains no initializers? For instance:

	protocol Something {
		static func give() -> Self?
	}
	class A: required Something {
		class func give() -> Self? { return nil }
	}
	
If I then derive B from A, am I required to override func give()?

	class B: A {
		// missing func 'give' or not?
	}

It would certainly make sense to want the protocol to be `static` in this case, to allow B.give to return a value of type A. But `required` doesn't seem to have any relevant meaning.


-- 
Michel Fortin
michel.fortin at michelf.ca
https://michelf.ca



More information about the swift-evolution mailing list