Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-10053] Protocols extending class types are not recognized as class types #52456

swift-ci opened this issue Mar 6, 2019 · 1 comment


Copy link

@swift-ci swift-ci commented Mar 6, 2019

Previous ID SR-10053
Radar rdar://problem/48702830
Original Reporter jbfit (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download


Swift compiler 4.2-RELEASE

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee None
Priority Medium

md5: 7098f9a0a7e244cda268053f1aa1d117


  • SR-55 non-@objc protocol existentials do not conform to their own protocol type

Issue Description:

class Alpha<T> where T: AnyObject {
    private let value: T
    init(_ value: T) {
        self.value = value

protocol Beta: AnyObject {}

class Gamma: Beta {}



  • The above code should compile: The requirement on generic `T` is that is that it extends from `AnyObject`. Since protocol `Beta` also extends from `AnyObject` it holds that any class `Foo` that implements protocol `Beta` will also extend from `AnyObject`


  • Code does not compile. Error message is error: "'Alpha' requires that 'Beta' be a class type"

Note: `class` and `AnyObject` are type-aliased to the same thing, so changing to `Beta: class` produces the same error

Also, this works as expected:

class Alpha<T> where T: AnyObject {
    private let value: T
    init(_ value: T) {
        self.value = value
class Beta {}
class Gamma: Beta {}
Copy link

@belkadan belkadan commented Mar 15, 2019

This is unfortunately correct behavior, because a protocol value isn't just a reference to the object; it also tracks information about how the type conforms to the protocol. See SR-55 and its dups for more discussion.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants