I'm playing around with Swift 5 a little and I was thinking if we can potentially lower the strictness of the error message in the future:
Cannot declare a public instance method in an extension with internal requirements
protocol P {}
public class Base<Derived> {}
extension Base where Derived: P {
public func bar() { ... }
}
// CRTP: Thank you Slava 🍻
public final class SubClass: Base<SubClass>, P {}
Sure the extension shouldn't be visible for good reasons, but could we make the method available as a public member of module internal but public subclasses? In other words the extension won't be visible for the module user as an extension of Base
, but he may see an extension on all public subclasses of Base
with that method.
extension SubClass {
public func bar()
}
With CRTP I would need to rename the method on the super-class if I want to expose it in a subclass to the public, because overriding methods declared in an extension is not yet supported:
extension Base where Derived: P {
func _bar() { ... }
}
public final class SubClass: Base<SubClass>, P {
public func bar() {
_bar()
}
}