Skip to content

Add info about protocols with superclass requirement [SE-0156]#447

Open
valeriyvan wants to merge 5 commits into
swiftlang:mainfrom
valeriyvan:protocol-inherit-from-class
Open

Add info about protocols with superclass requirement [SE-0156]#447
valeriyvan wants to merge 5 commits into
swiftlang:mainfrom
valeriyvan:protocol-inherit-from-class

Conversation

@valeriyvan

@valeriyvan valeriyvan commented Feb 23, 2026

Copy link
Copy Markdown

Add info about protocols with superclass requirement.

Fixes: #445
Fixes: rdar://171309018

@amartini51

Copy link
Copy Markdown
Member

Thanks for taking the time to write up this addition to the documentation! Overall, I think these changes look good, but we should work through a couple minor questions.

This looks like the correct place to discuss this in the guide. Adding a code listing is good also, to match the existing tone of the docs in this chapter, and to show the syntax in an approachable way.

Can we find a less contrived example? The Renderer class is good — it feels real, which is like how other examples in the guide are written — but the code doesn't actually do anything.

What updates should we make to the reference? I don't see this syntax discussed in Protocol Declaration. If you'd like, I can write a draft of the changes there, or I can defer to you.

As a minor processes question, was this syntax new in SE-0156? I see discussion in that proposal of protocol composition, but not of this being newly allowed. Because of the similarities between conformance to a protocol and subclassing a superclass, I'm guessing this syntax might predate the Swift Evolution process. If it's not from that proposal, let's remove the SE number from the PR name.

@hborla Can you help identify a technical reviewer for this PR?

CC @invalidname who will be working on Swift docs when I'm out of the office starting sometime next month.

@valeriyvan

Copy link
Copy Markdown
Author

As a minor processes question, was this syntax new in SE-0156? I see discussion in that proposal of protocol composition, but not of this being newly allowed. Because of the similarities between conformance to a protocol and subclassing a superclass, I'm guessing this syntax might predate the Swift Evolution process. If it's not from that proposal, let's remove the SE number from the PR name.

SE-0156 didn't introduce new syntax but new semantics allowing existential to have specific class requirements: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0156-subclass-existentials.md#proposed-solution.

@valeriyvan

Copy link
Copy Markdown
Author

What updates should we make to the reference? I don't see this syntax discussed in Protocol Declaration. If you'd like, I can write a draft of the changes there, or I can defer to you.

I have applied minimal changes into Declarations.md as well. Please review.

@valeriyvan

Copy link
Copy Markdown
Author

Can we find a less contrived example? The Renderer class is good — it feels real, which is like how other examples in the guide are written — but the code doesn't actually do anything.

Updated example. Please have a look.

@valeriyvan

Copy link
Copy Markdown
Author

@amartini51 please review recent changes

See also commit commit 3dd5801 (Normalize punctuation in "prints"
comments, 2025-10-17) which normalized these comments.

References: 3dd5801
Formatting the body across multiple lines matches the way functions and
initializers are formatted elsewhere in the guide.

@amartini51 amartini51 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience while I was out on new-parent leave! This revised code listing looks good now. I'll follow up again to get a technical reviewer to look at these changes.

I pushed two minor/mechanical changes to your PR, and noted one paragraph in the reference that I don't think needs to be added.

Comment on lines +2462 to +2466
This is more restrictive than using `AnyObject`
because it limits conformance to a specific class hierarchy
rather than to any class type.
For more information,
see <doc:Protocols#Class-Only-Protocols>.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need this paragraph. The reference doesn't follow the three-part "intro, code listing, walkthrough" format that the guide uses. The reference generally doesn't link to the guide, except in places where only the chapter in the guide has the full information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add info about protocols with superclass requirement

2 participants