[SR-5880] Allow internal declarations in public protocol #48450
Labels
compiler
The Swift compiler in itself
conformances
Feature → protocol: protocol conformances
feature
A feature request or implementation
swift evolution proposal needed
Flag → feature: A feature that warrants a Swift evolution proposal
Additional Detail from JIRA
md5: 8c72427c6c260c57232fcd4732a6fb7a
Issue Description:
In writing a library that wraps a REST API, I find myself writing protocols for shared functionality. For instance, every
Resource
should have an ID and be serializable to the JSON format the REST API uses; but I only want some of those functions to be public! Since public protocols can not have internal declarations, I have to construct something like this:As we can see, I enforce that
doStuff
only ever receives values whose implementation I have created. Other modules can implement types conforming toFoo
but notInternalFoo
. However, the check is dynamic – meh.Compare with this (currently illegal) code:
Here, the intent is much clearer!
Of course, other modules can not implement types conforming to
Foo
now. I'd argue that this is what we want here; a compiler message along the lines of "Conformance to Foo is not possible because not all declarations are accessible" should be clear enough.We can also make this explicit by lifting the difference between
public
andopen
from classes: only protocols declaredopen
can be conformed to outside of their own module, but those can not haveinternal
declarations. This would be a source-breaking change, even though migration would be trivial: all protocols written with the current semantics would have to getopen
instead ofpublic
.The text was updated successfully, but these errors were encountered: